Numeric to Decimal
>>-+-DECIMAL-+--------------------------------------------------> '-DEC-----' >--(--numeric-expression--+----------------------------+--)---->< '-,--precision--+----------+-' '-,--scale-'
String to Decimal
>>-+-DECIMAL-+--------------------------------------------------> '-DEC-----' >--(--string-expression--+------------------------------------------------------+--)->< '-,--precision--+------------------------------------+-' '-,--scale--+----------------------+-' '-,--decimal-character-'
The DECIMAL function returns a decimal representation of:
Numeric to Decimal
The default for precision depends on the data type of the numeric-expression:
The result is the same number that would occur if the first argument were assigned to a decimal column or variable with a precision of p and a scale of s. An error is returned if the number of significant decimal digits required to represent the whole part of the number is greater than p-s.
String to Decimal
The result is the same number that would result from CAST(string-expression AS DECIMAL(p,s)). Digits are truncated from the end of the decimal number if the number of digits to the right of the decimal separator character is greater than the scale s. An error is returned if the number of significant digits to the left of the decimal character (the whole part of the number) in string-expression is greater than p-s. The default decimal character is not valid in the substring if the decimal-character argument is specified.
The result of the function is a decimal number with precision of p and scale of s, where p and s are the second and third arguments. If the first argument can be null, the result can be null; if the first argument is null, the result is the null value.
Syntax alternatives: When the precision is specified, the CAST specification should be used for maximal portability. For more information, see CAST specification.
SELECT EMPNO, DECIMAL(EDLEVEL,5,2) FROM EMPLOYEE
SELECT PRSTDATE + DECIMAL(:PERIOD,8) FROM PROJECT
UPDATE STAFF SET SALARY = DECIMAL(:newsalary, 9, 2, ',') WHERE ID = :empidThe value of SALARY becomes 21400.50.
(C) Copyright IBM Corporation 1992, 2006. All Rights Reserved.