ROUND

Rounds a numeric expression to the nearest precision.

See also CEILING / CEIL, FLOOR.

Syntax

ROUND( expr [, scale ] )

Arguments

Parameter Description
expr Numeric expression to round
scale Number of digits after the decimal point to round to. Defaults to 0 if not specified.

Returns

Always returns a floating point result.

Notes

  • If the input value is NULL, the result is NULL.

Examples

Rounding to the nearest integer

numbers=> SELECT ROUND(x) FROM (VALUES (0.0001), (PI()), (-2.718281), (500.1234)) as t(x);
round
-----
 -0.0
  3.0
 -3.0
500.0

Rounding to 2 digits after the decimal point

numbers=> SELECT ROUND(x,2) FROM (VALUES (0.0001), (PI()), (-2.718281), (500.1234)) as t(x);
round
------
  -0.0
  3.14
 -2.72
500.12

FLOOR vs. CEILING / CEIL vs. ROUND

numbers=> SELECT FLOOR(x), CEIL(x), ROUND(x)
.      FROM (VALUES (0.0001), (-0.0001)
.           , (PI()), (-2.718281), (500.1234)) as t(x);
floor | ceil | round
------+------+------
    0 |    1 |    -0
    3 |    4 |     3
   -3 |   -2 |    -3
  500 |  501 |   500