The
DECFLOAT function returns a decimal floating-point representation of a value of a different data
type.
Numeric to decimal floating-point
Character to decimal floating-point
Boolean to decimal floating-point
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).
- boolean-expression
- An expression that returns a Boolean value (TRUE or FALSE).
The result is either 1 (for TRUE) or 0 (for FALSE).
- 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.
Result
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
- Increasing portability of applications:
If the first argument is numeric, or if the first argument is a string and the length argument is specified, use the
CAST specification
instead of this function to increase the portability of your applications.
- All numeric values are interpreted as integer, decimal, or floating-point constants and then cast to decimal floating-point.
The use of a floating-point constant can result in round-off errors and is therefore strongly discouraged.
Use the string to decimal floating-point version of the DECFLOAT function instead.
Examples
- 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
- The following statement returns the value 1 of data type DECFLOAT.
values DECFLOAT(TRUE)
- The following statement returns the value 0 of data type DECFLOAT.
values DECFLOAT(3>3)
© Copyright IBM Corp.