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

truncate, i64truncate

Library: fbudf

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

Changed in: 1.5, 2.1.3

Better alternative: Internal function TRUNC()

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

Result 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. The internal function TRUNC, available since Firebird 2.1, always truncates toward zero.

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. From Firebird 2.0 onward you can also perform this update with ALTER EXTERNAL FUNCTION.

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