Firebird Documentation IndexFirebird 1.5 Language Ref. UpdateExternal functions (UDFs) → truncate, i64truncate
Firebird Home Firebird Home Prev: substrlenFirebird Documentation IndexUp: External functions (UDFs)Next: Notes

truncate, i64truncate

Library: fbudf

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

Changed in: 1.5, 1.5.6

Description: These functions return the whole-number portion of their (scaled numeric/decimal) argument. They do not work with floats or doubles.

Return type: INTEGER / NUMERIC(18)

Syntax: 

truncate    (number)
i64truncate (bignumber)

Caution

Both functions round to the nearest whole number that is lower than or equal to the argument. This means that negative numbers are also “truncated” downward. For instance, truncate(-2.37) returns -3.

Bug alert

Contrary to what's mentioned above, in versions 1.0 through 1.5.5 anything between -1 and 0 is truncated to 0. This anomaly has been corrected in Firebird 1.5.6 and above (as a backport from 2.5).

Declarations: 

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

DECLARE EXTERNAL FUNCTION Truncate
   INT BY DESCRIPTOR, INT BY DESCRIPTOR
   RETURNS PARAMETER 2
   ENTRY_POINT 'truncate' MODULE_NAME 'fbudf'
DECLARE EXTERNAL FUNCTION i64Truncate
   NUMERIC(18) BY DESCRIPTOR, NUMERIC(18) BY DESCRIPTOR
   RETURNS PARAMETER 2
   ENTRY_POINT 'truncate' MODULE_NAME 'fbudf'

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

DECLARE EXTERNAL FUNCTION Truncate
   INT BY DESCRIPTOR, INT BY DESCRIPTOR
   RETURNS PARAMETER 2
   ENTRY_POINT 'fbtruncate' MODULE_NAME 'fbudf'
DECLARE EXTERNAL FUNCTION i64Truncate
   NUMERIC(18) BY DESCRIPTOR, NUMERIC(18) BY DESCRIPTOR
   RETURNS PARAMETER 2
   ENTRY_POINT 'fbtruncate' 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: substrlenFirebird Documentation IndexUp: External functions (UDFs)Next: Notes
Firebird Documentation IndexFirebird 1.5 Language Ref. UpdateExternal functions (UDFs) → truncate, i64truncate