DB2 10.5 for Linux, UNIX, and Windows

DECFLOAT scalar function

The DECFLOAT function returns a decimal floating-point representation of a number or a string representation of a number.

Read syntax diagramSkip visual syntax diagram
Numeric to Decimal floating-point

                                    .-,--34-.      
>>-DECFLOAT--(--numeric-expression--+-------+--)---------------><
                                    '-,--16-'      

Read syntax diagramSkip visual syntax diagram
Character to Decimal floating-point

                                   .-,--34--+----------------------+-.      
                                   |        '-,--decimal-character-' |      
>>-DECFLOAT--(--string-expression--+---------------------------------+--)-><
                                   '-,--16--+----------------------+-'      
                                            '-,--decimal-character-'        

The schema is SYSIBM.

numeric-expression
An expression that returns a value of any built-in numeric data type.
string-expression
An expression that returns a value that is a character-string or Unicode graphic-string representation of a number with a length not greater than the maximum length of a character constant. The data type of string-expression must not be CLOB or DBCLOB (SQLSTATE 42884). Leading and trailing blanks are removed from the string. The resulting substring is folded to uppercase and must conform to the rules for forming an integer, decimal, floating-point, or decimal floating-point constant (SQLSTATE 22018) and not be greater than 42 bytes (SQLSTATE 42820).
34 or 16
Specifies the number of digits of precision for the result. The default is 34.
decimal-character
Specifies the single-byte character constant used to delimit the decimal digits in character-expression from the whole part of the number. The character cannot be a digit, plus (+), minus (-), or blank, and it can appear at most once in character-expression.

The result is the same number that would result from CAST(string-expression AS DECFLOAT(n)) or CAST(numeric-expression AS DECFLOAT(n)). Leading and trailing blanks are removed from the string.

The result of the function is a decimal floating-point number with the implicitly or explicitly specified number of digits of precision. If the first argument can be null, the result can be null; if the first argument is null, the result is the null value.

If necessary, the source is rounded to the precision of the target. The CURRENT DECFLOAT ROUNDING MODE special register determines the rounding mode.

Notes

Example

Use the DECFLOAT function in order to force a DECFLOAT data type to be returned in a select-list for the EDLEVEL column (data type = SMALLINT) in the EMPLOYEE table. The EMPNO column should also appear in the select list.
SELECT EMPNO, DECFLOAT(EDLEVEL,16) 
FROM EMPLOYEE