DECIMAL or DEC

Click to skip syntax diagram

Numeric to Decimal

Read syntax diagramSkip visual syntax diagram>>-+-DECIMAL-+-------------------------------------------------->
   '-DEC-----'
 
>--(--numeric-expression--+----------------------------+--)----><
                          '-,--precision--+----------+-'
                                          '-,--scale-'
 

String to Decimal

Read syntax diagramSkip visual syntax diagram>>-+-DECIMAL-+-------------------------------------------------->
   '-DEC-----'
 
>--(--string-expression--+------------------------------------------------------+--)-><
                         '-,--precision--+------------------------------------+-'
                                         '-,--scale--+----------------------+-'
                                                     '-,--decimal-character-'
 

The DECIMAL function returns a decimal representation of:

Numeric to Decimal

numeric-expression
An expression that returns a value of any built-in numeric data type.
precision
An integer constant with a value greater than or equal to 1 and less than or equal to 63.

The default for precision depends on the data type of the numeric-expression:

scale
An integer constant that is greater than or equal to 0 and less than or equal to precision. If not specified, the default is 0.

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

string-expression
An expression that returns a character-string or graphic-string representation of a number. Leading and trailing blanks are eliminated and the resulting string must conform to the rules for forming a floating-point, integer, or decimal constant.
precision
An integer constant that is greater than or equal to 1 and less than or equal to 63. If not specified, the default is 15.
scale
An integer constant that is greater than or equal to 0 and less than or equal to precision. If not specified, the default is 0.
decimal-character
Specifies the single-byte character constant that is used to delimit the decimal digits in string-expression from the whole part of the number. The character must be a period or comma. If decimal-character is not specified, the decimal point is the default decimal separator character. For more information, see Decimal point.

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.

Note

Syntax alternatives: When the precision is specified, the CAST specification should be used for maximal portability. For more information, see CAST specification.

Examples