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.

Figure 1: 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: decimals
SELECT ROUND(102.3456, 2);
-- positive: number negative: decimals
SELECT ROUND(112.3456, -1);
-- neagtive: number positive: decimals
SELECT ROUND(-102.3456, 3);
-- neagtive: number negative: decimals
select ROUND(-6.13, -1);
-- omit decimals
select ROUND(12.234);

Free Resources