DECFLOAT

The DECFLOAT function returns a decimal floating-point representation of either a number or a character string representation of a number, a decimal number, an integer, a floating-point number, or a decimal floating-point number.

Numeric to DECFLOAT:

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

String to DECFLOAT:

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

The schema is SYSIBM.

Numeric to DECFLOAT

numeric-expression
An expression that returns a value of any built-in numeric data type.
34 or 16
Specifies the number of digits of precision for the result. The default is 34.

String to DECFLOAT

string-expression
An expression that returns a value of a character or graphic string (except a CLOB or DBCLOB) with a length attribute that is not greater than 255 bytes. Leading and trailing blanks are eliminated, and the resulting string is folded to uppercase. The expression must conform to the rules for forming a floating-point, decimal floating-point, integer, or decimal constant.

Use the string-expression syntax variation to specify a negative zero as a constant, or to preserve the precision of a floating point constant.

34 or 16
Specifies the number of digits of precision for the result. The default is 34.

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, and the resulting substring must conform to the rules for forming a string representation of an SQL decimal-floating point constant.

If necessary, the source is rounded to the precision of the target.

For static SQL statements other than CREATE VIEW, the ROUNDING bind option or the native SQL procedure option determines the rounding mode.

For dynamic SQL statements (and static CREATE VIEW statements), the special register CURRENT DECFLOAT ROUNDING MODE determines the rounding mode.

The result of the function is a DECFLOAT with the implicitly or explicitly specified number of digits of precision.

The result can be null; if the first argument is null, the result is the null value.

Note: To increase the portability of applications, use the CAST specification. For more information, see CAST specification.
Example: When a keyword is used for a special value that is expressed as a constant in a context where the keyword could be interpreted as a name, the DECFLOAT function can be used to explicitly cast the value to decimal-floating point. Assume that MYTAB contains columns C1 and SNAN, and that you want to reference the decimal floating-point value for infinity in the same SQL statement. Use the DECFLOAT function to explicitly cast SNAN as a decimal floating-point value to ensure that it is not interpreted as the name of a column, parameter or variable:
     SELECT INFINITY                 -- column named SNAN
         FROM MYTAB
       WHERE C1 = DECFLOAT ('sNaN' ) -- comparison is made with the
                                     -- decimal floating-point sNaN value