![]() |
VOOZH | about |
The SQL Server ROUND() function rounds off a specified number to a decimal place. If the length is negative and larger than the number of digits before the decimal point, ROUND returns 0.
The ROUND() function in SQL Server rounds off a number to a specified decimal place. It accepts positive, negative, and zero values.
This function always returns the number after rounding to the specified decimal places.
The ROUND function syntax is:
ROUND(number, decimals, operation)
This method accepts three parameters, as given below :
Let's look at some example of the ROUND function in SQL Server.
In this example, we are rounding off a number up to next two decimal places.
Query
SELECT ROUND(12.3456, 2);Output :
12.3500In this example, we are rounding off 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.
Query:
SELECT ROUND(12.3456, 2, 1);Output :
12.3400In this example, we are using ROUND() function with negative paramter.
Query:
DECLARE @Parameter_Value FLOAT;
SET @Parameter_Value = -2;
SELECT ROUND(123.4567, @Parameter_Value);
Output :
100.0000In this example, we are rounding number to the zero number of decimal places.
Query:
SELECT ROUND(123.467, 0);Output :
123.000
- The ROUND() function in SQL Server is used to round off a specified number to a specified number of decimal places.
- It accepts various types of numbers, including positive, negative, and zero.
- The return type of the ROUND() function depends on the input number type.
- The ROUND() function uses the rounding-to-the-nearest-digit algorithm.