You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is an [expression](../../t-sql/language-elements/expressions-transact-sql.md) of the exact numeric or approximate numeric data type category.
36
-
37
-
*length*
38
-
Is the precision to which *numeric_expression* is to be rounded. *length* must be an expression of type **tinyint**, **smallint**, or **int**. When *length* is a positive number, *numeric_expression* is rounded to the number of decimal positions specified by *length*. When *length* is a negative number, *numeric_expression* is rounded on the left side of the decimal point, as specified by *length*.
39
-
40
-
*function*
41
-
Is the type of operation to perform. *function* must be **tinyint**, **smallint**, or **int**. When *function* is omitted or has a value of 0 (default), *numeric_expression* is rounded. When a value other than 0 is specified, *numeric_expression* is truncated.
42
-
43
-
## Return Types
44
-
Returns the following data types.
45
-
46
-
|Expression result|Return type|
47
-
|-----------------------|-----------------|
48
-
|**tinyint**|**int**|
49
-
|**smallint**|**int**|
50
-
|**int**|**int**|
51
-
|**bigint**|**bigint**|
52
-
|**decimal** and **numeric** category (p, s)|**decimal(p, s)**|
53
-
|**money** and **smallmoney** category|**money**|
54
-
|**float** and **real** category|**float**|
55
-
56
-
## Remarks
57
-
ROUND always returns a value. If *length* is negative and larger than the number of digits before the decimal point, ROUND returns 0.
58
-
59
-
|Example|Result|
60
-
|-------------|------------|
61
-
|ROUND(748.58, -4)|0|
62
-
63
-
ROUND returns a rounded *numeric_expression*, regardless of data type, when *length* is a negative number.
64
-
65
-
|Examples|Result|
66
-
|--------------|------------|
67
-
|ROUND(748.58, -1)|750.00|
68
-
|ROUND(748.58, -2)|700.00|
69
-
|ROUND(748.58, -3)|Results in an arithmetic overflow, because 748.58 defaults to decimal(5,2), which cannot return 1000.00.|
70
-
|To round up to 4 digits, change the data type of the input. For example:<br /><br /> `SELECT ROUND(CAST (748.58 AS decimal (6,2)),-3);`|1000.00|
71
-
72
-
## Examples
73
-
74
-
### A. Using ROUND and estimates
75
-
The following example shows two expressions that demonstrate by using `ROUND` the last digit is always an estimate.
An [expression](../../t-sql/language-elements/expressions-transact-sql.md) of the exact numeric or approximate numeric data type category.
40
+
41
+
#### *length*
42
+
43
+
The precision to which *numeric_expression* is to be rounded. *length* must be an expression of type **tinyint**, **smallint**, or **int**. When *length* is a positive number, *numeric_expression* is rounded to the number of decimal positions specified by *length*. When *length* is a negative number, *numeric_expression* is rounded on the left side of the decimal point, as specified by *length*.
44
+
45
+
#### *function*
46
+
47
+
The type of operation to perform. *function* must be **tinyint**, **smallint**, or **int**. When *function* is omitted or has a value of `0` (default), *numeric_expression* is rounded. When a value other than `0` is specified, *numeric_expression* is truncated.
48
+
49
+
## Return types
50
+
51
+
Returns the following data types.
52
+
53
+
| Expression result | Return type |
54
+
| --- | --- |
55
+
|**tinyint**|**int**|
56
+
|**smallint**|**int**|
57
+
|**int**|**int**|
58
+
|**bigint**|**bigint**|
59
+
|**decimal** and **numeric** category (p, s) |**decimal(p, s)**|
60
+
|**money** and **smallmoney** category |**money**|
61
+
|**float** and **real** category |**float**|
62
+
63
+
## Remarks
64
+
65
+
-`ROUND` always returns a value. If *length* is negative and larger than the number of digits before the decimal point, `ROUND` returns `0`.
66
+
67
+
| Example | Result |
68
+
| --- | --- |
69
+
|`ROUND(748.58, -4)`| 0 |
70
+
71
+
-`ROUND` returns a rounded *numeric_expression*, regardless of data type, when *length* is a negative number.
72
+
73
+
| Examples | Result |
74
+
| --- | --- |
75
+
|`ROUND(748.58, -1)`| 750.00 |
76
+
|`ROUND(748.58, -2)`| 700.00 |
77
+
|`ROUND(748.58, -3)`| Results in an arithmetic overflow, because 748.58 defaults to **decimal(5, 2)**, which can't return `1000.00`. |
78
+
79
+
- To round up to four digits, change the data type of the input. For example:
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.
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.
0 commit comments