The exact numeric types—dec, decimal, and numeric—begin with an optional positive or negative sign and can include a decimal point. The value of exact numeric data depends on the column’s decimal precision and scale, which you specify using this syntax:
datatype [(precision [, scale ])]
Adaptive Server treats each combination of precision and scale as a distinct datatype. For example, numeric (10,0) and numeric (5,0) are two separate datatypes. The precision and scale determine the range of values that can be stored in a decimal or numeric column:
The precision specifies the maximum number of decimal digits that can be stored in the column. It includes all digits to the right and left of the decimal point. You can specify a precision ranging from 1 to 38 digits, or use the default precision of 18 digits.
The scale specifies the maximum number of digits that can be stored to the right of the decimal point. The scale must be less than or equal to the precision. You can specify a scale ranging from 0 to 38 digits, or use the default scale of 0 digits.
If a value exceeds the column’s precision or scale, Adaptive Server flags the entry as an error. Here are some examples of valid dec and numeric data:
Data entered |
Datatype |
Precision |
Scale |
Value |
---|---|---|---|---|
12.345 |
numeric(5,3) |
5 |
3 |
12.345 |
-1234.567 |
dec(8,4) |
8 |
4 |
-1234.567 |
The following entries result in errors because they exceed the column’s precision or scale:
Data entered |
Datatype |
Precision |
Scale |
---|---|---|---|
1234.567 |
numeric(3,3) |
3 |
3 |
1234.567 |
decimal(6) |
6 |
1 |