Firebird Documentation Index → Firebird 2.1 Language Ref. Update → External functions (UDFs) → 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
)
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(
returns -2.37
)-3
. The internal function TRUNC, available since Firebird 2.1, always truncates toward zero.
Contrary to what's mentioned above, in versions 2.1, 2.1.1 and 2.1.2 anything between -1 and 0 is truncated to 0. This anomaly has been corrected in Firebird 2.1.3 and above.
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.
Firebird Documentation Index → Firebird 2.1 Language Ref. Update → External functions (UDFs) → truncate, i64truncate |