The
DECFLOAT function returns a decimal floating-point representation
of a number or a string representation of a number.
Numeric to Decimal floating-point
.-,--34-.
>>-DECFLOAT--(--numeric-expression--+-------+--)---------------><
'-,--16-'
Character to Decimal floating-point
.-,--34--+----------------------+-.
| '-,--decimal-character-' |
>>-DECFLOAT--(--string-expression--+---------------------------------+--)-><
'-,--16--+----------------------+-'
'-,--decimal-character-'
- 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
- The CAST specification should be used to increase
the portability of applications. For more information, see "CAST
specification".
- 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.
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