truncate, i64truncate
<< substrlen | FB 2.0 Language Reference | Appendix A: Notes >>
truncate
, i64truncate
Library: fbudf
Added in: 1.0 (Win), 1.5 (Linux)
Changed in: 1.5, 2.0.6
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
.
Bug alert: Contrary to what's mentioned above, in versions 2.0 through 2.0.5 anything between -1 and 0 is truncated to 0. This anomaly has been corrected in Firebird 2.0.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. From Firebird 2.0 onward you can also perform this update with ALTER EXTERNAL FUNCTION
.
back to top of page
<< substrlen | FB 2.0 Language Reference | Appendix A: Notes >>