8.2.19. ROUND()

Available in

DSQL, PSQL

Possible name conflict

YES → Read details

Syntax

  1. ROUND (number [, scale])
Table 115. ROUND Function Parameters
ParameterDescription

number

An expression of a numeric type

scale

An integer specifying the number of decimal places toward which rounding is to be performed, e.g.:

  •  2 for rounding to the nearest multiple of 0.01

  •  1 for rounding to the nearest multiple of 0.1

  •  0 for rounding to the nearest whole number

  • -1 for rounding to the nearest multiple of 10

  • -2 for rounding to the nearest multiple of 100

Result type

INTEGER, (scaled) BIGINT or DOUBLE PRECISION

Description

Rounds a number to the nearest integer. If the fractional part is exactly 0.5, rounding is upward for positive numbers and downward for negative numbers. With the optional scale argument, the number can be rounded to powers-of-ten multiples (tens, hundreds, tenths, hundredths, etc.) instead of just integers.

If you are used to the behaviour of the external function ROUND, please notice that the internal function always rounds halves away from zero, i.e. downward for negative numbers.

Examples

If the scale argument is present, the result usually has the same scale as the first argument:

  1. ROUND(123.654, 1) -- returns 123.700 (not 123.7)
  2. ROUND(8341.7, -3) -- returns 8000.0 (not 8000)
  3. ROUND(45.1212, 0) -- returns 45.0000 (not 45)

Otherwise, the result scale is 0:

  1. ROUND(45.1212) -- returns 45