Open In App

ROUND() Function in SQL Server

ROUND() function :
This function in SQL Server is used to round off a specified number to a specified decimal places.

Features :



Syntax :

ROUND(number, decimals, operation)

Parameter :
This method accepts three parameters as given below :



Returns :
It returns the number after rounded to the specified places.

Example-1 :
Getting a rounded number up to next two decimal places.

SELECT ROUND(12.3456, 2);

Output :

12.3500

Example-2 :
Getting the number to the next two decimal places with the operational parameter 1 which says only to truncate the specified number (-23.456) to the given decimal places i, e., 2.

SELECT ROUND(12.3456, 2, 1);

Output :

12.3400

Example-3 :
Using ROUND() function with a variable and getting the rounded number to -2 decimal place.

DECLARE @Parameter_Value FLOAT;
SET @Parameter_Value = -2;
SELECT ROUND(123.4567, @Parameter_Value);

Output :

100.0000

Example-4 :

Getting the rounded number to the zero number of decimal places.

SELECT ROUND(123.467, 0);

Output :

123.000

Example-5 :
Using ROUND() function with variables and getting the rounded number to the 2 decimal places.

DECLARE @Number_Value FLOAT;
DECLARE @Decimals_Value INT;
SET @Number_Value = -23.456;
SET @Decimals_Value = 2;
SELECT ROUND(@Number_Value, @Decimals_Value);

Output :

-23.460000000000001

Example-6 :
Getting the number to the next two decimal places with the operational parameter 1 which says only to truncate the specified number (-23.456) to the given decimal places i.e., 2.

SELECT ROUND(-23.456, 2, 1);

Output :

-23.450

Application :
This function is used to return the number after rounded to the specified places.

Article Tags :
SQL