Skip to content
Related Articles
Get the best out of our app
GeeksforGeeks App
Open App
geeksforgeeks
Browser
Continue

Related Articles

ROUND() Function in SQL Server

Improve Article
Save Article
Like Article
Improve Article
Save Article
Like Article

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

Features :

  • This function is used to round off a specified number to a specified decimal places.
  • This function accepts only all type of numbers i.e., positive, negative, zero.
  • This function accepts fraction numbers.
  • This function always returns the number after rounded to the specified decimal places.

Syntax :

ROUND(number, decimals, operation)

Parameter :
This method accepts three parameters as given below :

  • number : Specified number to be rounded off.
  • decimals : Specified number of decimal places up to which the given number is to be rounded.
  • operation : This is optional parameter. If it’s value is 0, it rounds the result to the number of decimal. If another value than 0, it truncates the result to the number of decimals. Default value is 0

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.

My Personal Notes arrow_drop_up
Last Updated : 30 Dec, 2020
Like Article
Save Article
Similar Reads