DB2 Scalar functions - QUANTIZE
The QUANTIZE function returns a decimal floating-point value that is equal in value (except for any rounding) and sign to numeric-expression and that has an exponent equal to the exponent of exp-expression.
The number of digits (16 or 34) is the same as the number of digits in numeric-expression.
The schema is SYSIBM.
The coefficient of the result is derived from that of numeric-expression. It is rounded, if necessary (if the exponent is being increased), multiplied by a power of ten (if the exponent is being decreased), or remains unchanged (if the exponent is already equal to that of exp-expression).
The CURRENT DECFLOAT ROUNDING MODE special register determines the rounding mode.
Unlike other arithmetic operations on the decimal floating-point data type, if the length of the coefficient after the quantize operation is greater than the precision specified by exp-expression, the result is NaN and a warning is returned (SQLSTATE 0168D). This ensures that, unless there is a warning condition, the exponent of the result of QUANTIZE is always equal to that of exp-expression.
The result of the function is a DECFLOAT(16) value if both arguments are DECFLOAT(16). Otherwise, the result of the function is a DECFLOAT(34) value. The result can be null; if any argument is null, the result is the null value.
QUANTIZE(2.17, DECFLOAT(0.001)) = 2.170 QUANTIZE(2.17, DECFLOAT(0.01)) = 2.17 QUANTIZE(2.17, DECFLOAT(0.1)) = 2.2 QUANTIZE(2.17, DECFLOAT('1E+0')) = 2 QUANTIZE(2.17, DECFLOAT('1E+1')) = 0E+1 QUANTIZE(2, DECFLOAT(INFINITY)) = NaN -- warning QUANTIZE(0, DECFLOAT('1E+5')) = 0E+5 QUANTIZE(217, DECFLOAT('1E-1')) = 217.0 QUANTIZE(217, DECFLOAT('1E+0')) = 217 QUANTIZE(217, DECFLOAT('1E+1')) = 2.2E+2 QUANTIZE(217, DECFLOAT('1E+2')) = 2E+2
CHAR(QUANTIZE(-0.1, DECFLOAT(1))) = -0