ROUND()

<< RIGHT() | FB 2.5 Language Reference | RPAD() >>
<< RIGHT() | FB 2.1 Language Reference | RPAD() >>

ROUND()

Available in: DSQL, PSQL

Added in: 2.1

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.

Result type: INTEGER, (scaled) BIGINT or DOUBLE

Syntax

 ROUND (<number> [, <scale>])

 <number> ::= a numerical expression
 <scale>  ::= an integer specifying the number of decimal places 
              toward which should be rounded, 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

Notes:

  • If the SCALE argument is present, the result usually has the same scale as the first argument, e.g.
    • ROUND(123.654, 1) returns 123.700 (not 123.7)
    • ROUND(8341.7, -3) returns 8000.0 (not 8000)
    • ROUND(45.1212, 0) returns 45.0000 (not 45)
Otherwise, the result scale is 0:
  • ROUND(45.1212) returns 45

Important:

  • If the external function ROUND is declared in your database, it will override the internal function. To make the internal function available, DROP or ALTER the external function (UDF).
  • 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.

See also:
TRUNCATE

back to top of page
<< RIGHT() | FB 2.5 Language Reference | RPAD() >>
<< RIGHT() | FB 2.1 Language Reference | RPAD() >>