In this post explains how to use the ROUND function in SQL Server (Transact-SQL) with syntax and examples.
In SQL Server (Transact-SQL), the ROUND function returns a number rounded to a certain number of decimal places.
The syntax for the ROUND function in SQL Server (Transact-SQL) is:
ROUND( number, decimal_places [, operation ] )
The number to round.
The number of decimal places rounded to. This value must be a positive or negative integer. If this parameter is omitted, the ROUND function will round the number to 0 decimal places.
Optional. The operation can be either 0 or any other numeric value. When it is 0 (or this parameter is omitted), the ROUND function will round the result to the number of decimal_places. If operation is any value other than 0, the ROUND function will truncate the result to the number of decimal_places.
The ROUND function can be used in the following versions of SQL Server (Transact-SQL):
Let's look at some SQL Server ROUND function examples and explore how to use the ROUND function in SQL Server (Transact-SQL).
For example:
SELECT ROUND(125.315, 2);
Output: 125.320 (result is rounded because 3rd parameter is omitted)
SELECT ROUND(125.315, 2, 0);
Output: 125.320 (result is rounded because 3rd parameter is 0)
SELECT ROUND(125.315, 2, 1);
Output: 125.310 (result is truncated because 3rd parameter is non-zero)
SELECT ROUND(125.315, 1);
Output: 125.300 (result is rounded because 3rd parameter is omitted)
SELECT ROUND(125.315, 0);
Output: 125.000 (result is rounded because 3rd parameter is omitted)
SELECT ROUND(125.315, -1);
Output: 130.000 (result is rounded because 3rd parameter is omitted)
SELECT ROUND(125.315, -2);
Output: 100.000 (result is rounded because 3rd parameter is omitted)