truncate, i64truncate

<< tanh | FB 2.5 Language Reference | Appendix A: Notes >>
<< tanh | FB 2.1 Language Reference | Appendix A: 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.

Bug alert: 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.

back to top of page
<< tanh | FB 2.5 Language Reference | Appendix A: Notes >>
<< tanh | FB 2.1 Language Reference | Appendix A: Notes >>