Firebird Documentation IndexFirebird 1.5 Language Ref. UpdateExternal functions (UDFs) → round, i64round
Firebird Home Firebird Home Prev: rightFirebird Documentation IndexUp: External functions (UDFs)Next: rpad

round, i64round

Library: fbudf

Added in: 1.0 (Win), 1.5 (Linux)

Changed in: 1.5, 1.5.6

Description: These functions return the whole number that is nearest to their (scaled numeric/decimal) argument. They do not work with floats or doubles.

Return type: INTEGER / NUMERIC(18,4)

Syntax: 

round    (number)
i64round (bignumber)

Caution

Halves are always rounded upward, i.e. away from zero for positive numbers and toward zero for negative numbers. For instance, 3.5 is rounded to 4, but -3.5 is rounded to -3.

Bug alert

In versions 1.0 through 1.5.5, these functions are broken for negative numbers:

  • Anything between 0 and -0.6 (that's right: -0.6, not -0.5) is rounded to 0.

  • Anything between -0.6 and -1 is rounded to +1 (plus 1).

  • Anything between -1 and -1.6 is rounded to -1.

  • Anything between -1.6 and -2 is rounded to -2.

  • Etcetera.

Fixed in 1.5.6 (backport from 2.5).

Declarations: 

In Firebird 1.0.x, the entry point for both functions is round:

DECLARE EXTERNAL FUNCTION Round
   INT BY DESCRIPTOR, INT BY DESCRIPTOR
   RETURNS PARAMETER 2
   ENTRY_POINT 'round' MODULE_NAME 'fbudf'
DECLARE EXTERNAL FUNCTION i64Round
   NUMERIC(18,4) BY DESCRIPTOR, NUMERIC(18,4) BY DESCRIPTOR
   RETURNS PARAMETER 2
   ENTRY_POINT 'round' MODULE_NAME 'fbudf'

In Firebird 1.5, the entry point has been renamed to fbround:

DECLARE EXTERNAL FUNCTION Round
   INT BY DESCRIPTOR, INT BY DESCRIPTOR
   RETURNS PARAMETER 2
   ENTRY_POINT 'fbround' MODULE_NAME 'fbudf'
DECLARE EXTERNAL FUNCTION i64Round
   NUMERIC(18,4) BY DESCRIPTOR, NUMERIC(18,4) BY DESCRIPTOR
   RETURNS PARAMETER 2
   ENTRY_POINT 'fbround' MODULE_NAME 'fbudf'

If you move an existing database from Firebird 1.0.x to 1.5 or higher, drop any existing *round and *truncate declarations and declare them anew, using the updated entry point names.

Prev: rightFirebird Documentation IndexUp: External functions (UDFs)Next: rpad
Firebird Documentation IndexFirebird 1.5 Language Ref. UpdateExternal functions (UDFs) → round, i64round