FirebirdSQL logo

Examples of NORMALIZE_DECFLOAT

-- will return 12
select normalize_decfloat(12.00)
from rdb$database;

-- will return 1.2E+2
select normalize_decfloat(120)
from rdb$database;

QUANTIZE()

Returns a value that is equal in value — except for rounding — to the first argument, but with the same exponent as the second argument

Result type

DECFLOAT

Syntax
QUANTIZE (decfloat_value, exp_value)
Table 1. QUANTIZE Function Parameters
Parameter Description

decfloat_value

Value or expression to quantize;needs to be of type DECFLOAT, or cast-compatible with DECFLOAT

exp_value

Value or expression to use for its exponent;needs to be of type DECFLOAT, or cast-compatible with DECFLOAT

QUANTIZE returns a DECFLOAT value that is equal in value and sign (except for rounding) to decfloat_value, and that has an exponent equal to the exponent of exp_value.The type of the return value is DECFLOAT(16) if both arguments are DECFLOAT(16), otherwise the result type is DECFLOAT(34).

Note

The target exponent is the exponent used in the Decimal64 or Decimal128 storage format of DECFLOAT of exp_value.This is not necessarily the same as the exponent displayed in tools like isql.For example, the value 1.23E+2 is coefficient 123 and exponent 0, while 1.2 is coefficient 12 and exponent -1.

If the exponent of decfloat_value is greater than the one of exp_value, the coefficient of decfloat_value is multiplied by a power of ten, and its exponent decreased.If the exponent is smaller, then its coefficient is rounded using the current decfloat rounding mode, and its exponent is increased.

When it is not possible to achieve the target exponent because the coefficient would exceed the target precision (16 or 34 decimal digits), either a “Decfloat float invalid operation” error is raised or NaN is returned (depending on the current decfloat traps configuration).

There are almost no restrictions on the exp_value.However, in almost all usages, NaN/sNaN/Infinity will produce an exception (unless allowed by the current decfloat traps configuration), NULL will make the function return NULL, and so on.