SQL Server Tutorial SQL Server Advanced SQL Server Database SQL Server References

SQL Server ROUND() Function



The SQL Server (Transact-SQL) ROUND() function returns a number rounded to the specified number of decimal places. If decimal_places is a negative number, this function will make digits to the left of the decimal place 0 values.

Syntax

ROUND(number, decimal_places, operation)

Parameters

number Required. Specify the number to round.
decimal_places Required. Specify the number of decimal places to round. This value must be a positive or negative integer. When it is a positive number, the number is rounded to the specified decimal places. When it is a negative number, the number is rounded on the left side of the decimal point, as specified by it.
operation Optional. Specify the type of operation to perform. When it is omitted or has a value of 0 (default), the number is rounded. When a value other than 0 is specified, the number is truncated.

Return Value

Returns the rounded value of the number to specified decimal_places.

Example 1:

The example below shows the usage of ROUND() function.

SELECT ROUND(1234.5678, 0);
Result: 1235.0000

SELECT ROUND(1234.5678, 1);
Result: 1234.6000

SELECT ROUND(1234.5678, 2);
Result: 1234.5700

SELECT ROUND(1234.5678, 3);
Result: 1234.5680

SELECT ROUND(1234.5678, -1);
Result: 1230.0000

SELECT ROUND(1234.5678, -2);
Result: 1200.0000

SELECT ROUND(1234.5678, 2, 0);
Result: 1234.5700

--using round() function to truncate
SELECT ROUND(1234.5678, 2, 1);
Result: 1234.5600

Example 2:

Consider a database table called Sample with the following records:

Datax
Data 1-3.75567
Data 2-5.3867
Data 313.9804
Data 493.1601
Data 548.1322

The statement given below can be used to round the records of column x to 2 decimal places.

SELECT *, ROUND(x, 2) AS ROUND_Value FROM Sample;

This will produce the result as shown below:

DataxROUND_Value
Data 1-3.75567-3.76000
Data 2-5.3867-5.3900
Data 313.980413.9800
Data 493.160193.1600
Data 548.132248.1300

❮ SQL Server Functions