21.10.2013 Views

Firebird 2.1 Language Reference Update

Firebird 2.1 Language Reference Update

Firebird 2.1 Language Reference Update

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

See sright.<br />

Library: fbudf<br />

Added in: 1.0 (Win), 1.5 (Linux)<br />

Changed in: 1.5, <strong>2.1</strong>.3<br />

Better alternative: Internal function ROUND()<br />

External functions (UDFs)<br />

right<br />

round, i64round<br />

Description: These functions return the whole number that is nearest to their (scaled numeric/decimal) argument.<br />

They do not work with floats or doubles.<br />

Result type: INTEGER / NUMERIC(18,4)<br />

Syntax:<br />

round (number)<br />

i64round (bignumber)<br />

Declarations:<br />

Caution<br />

Halves are always rounded upward, i.e. away from zero for positive numbers and toward zero for negative<br />

numbers. For instance, 3.5 is rounded to 4, but -3.5 is rounded to -3. The internal function ROUND, available<br />

since <strong>Firebird</strong> <strong>2.1</strong>, rounds all halves away from zero.<br />

Bug alert<br />

In versions <strong>2.1</strong>, <strong>2.1</strong>.1 and <strong>2.1</strong>.2, these functions are broken for negative numbers:<br />

• Anything between 0 and -0.6 (that's right: -0.6, not -0.5) is rounded to 0.<br />

• Anything between -0.6 and -1 is rounded to +1 (plus 1).<br />

• Anything between -1 and -1.6 is rounded to -1.<br />

• Anything between -1.6 and -2 is rounded to -2.<br />

• Etcetera.<br />

Fixed in <strong>2.1</strong>.3.<br />

In <strong>Firebird</strong> 1.0.x, the entry point for both functions is round:<br />

DECLARE EXTERNAL FUNCTION Round<br />

INT BY DESCRIPTOR, INT BY DESCRIPTOR<br />

RETURNS PARAMETER 2<br />

ENTRY_POINT 'round' MODULE_NAME 'fbudf'<br />

185

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!