What is ROUND() in SQL?
The ROUND() function rounds a number off to a specified number of decimal places.
Figure 1 shows a visual representation of the ROUND() function.
Syntax
ROUND(number, decimals)
Parameter
The ROUND() function has two parameters:
- A number to be rounded.
- A decimal place to which the above number needs to be rounded off – this is an optional parameter.
Return value
SIGN() returns the number rounded off to the specified number of decimal places.
If the decimals parameter is omitted, then
SIGN()returns the nearest integer value of a number sent as a parameter (no decimal places).
If you input a negative value (
n) in the decimalparameter, thenndigits to the left of the decimal point of the number parameter will change to0`.
Example
/*example showing how to use ROUND(X)*/-- positive: number positive: decimalsSELECT ROUND(102.3456, 2);-- positive: number negative: decimalsSELECT ROUND(112.3456, -1);-- neagtive: number positive: decimalsSELECT ROUND(-102.3456, 3);-- neagtive: number negative: decimalsselect ROUND(-6.13, -1);-- omit decimalsselect ROUND(12.234);