ROUND (Transact-SQL)
Returns a numeric value, rounded to the specified length or precision.
ROUND always returns a value. If length is negative and larger than the number of digits before the decimal point, ROUND returns 0.
Example | Result |
|---|---|
ROUND(748.58, -4) | 0 |
ROUND returns a rounded numeric_expression, regardless of data type, when length is a negative number.
Examples | Result |
|---|---|
ROUND(748.58, -1) | 750.00 |
ROUND(748.58, -2) | 700.00 |
ROUND(748.58, -3) | Results in an arithmetic overflow, because 748.58 defaults to decimal(5,2), which cannot return 1000.00. |
To round up to 4 digits, change the data type of the input. For example: SELECT ROUND(CAST (748.58 AS decimal (6,2)),-3); | 1000.00 |
A. Using ROUND and estimates
The following example shows two expressions that demonstrate by using ROUND the last digit is always an estimate.
SELECT ROUND(123.9994, 3), ROUND(123.9995, 3) GO
Here is the result set.
----------- ----------- 123.9990 124.0000
B. Using ROUND and rounding approximations
The following example shows rounding and approximations.
SELECT ROUND(123.4545, 2); GO SELECT ROUND(123.45, -2); GO
Here is the result set.
----------
123.4500
(1 row(s) affected)
--------
100.00
(1 row(s) affected)
C. Using ROUND to truncate
The following example uses two SELECT statements to demonstrate the difference between rounding and truncation. The first statement rounds the result. The second statement truncates the result.
SELECT ROUND(150.75, 0); GO SELECT ROUND(150.75, 0, 1); GO
Here is the result set.
-------- 151.00 (1 row(s) affected) -------- 150.00 (1 row(s) affected)