Decimals

Describes Decimal numbers

Decimal numbers are arbitrary precision numbers which do not use an exponent multiplier as reals may. Unlike reals, decimals must include every single digit. This eliminates the rounding problems of Reals but increases storage requirements for large values. As a general rule, decimals are used for currency amounts.

Each decimal value has a precision and a scale. The scale is the number digits to the right of the decimal separator. The precision is the total number of significant digits.

When you declare a decimal number you can do the following:
The following example shows various ways of declaring decimal values:
unspecified as Decimal
fixedScale as Decimal(2)
fixedBoth as Decimal(5, 2)

In this example, unspecified is of arbitrary precision and scale, fixedScale can be any number with only two digits to the right of the decimal digit (e.g. 600000.25), and fixedBoth can hold only numbers with up to two digits to the right of the decimal point for a total of 5 digits.

Decimal constants are a sequence of decimal digits followed by a period (.), followed by another sequence of decimal digits. Note that unlike Real constants, the number of digits to the right of the decimal point is significant and specifies the scale of the constant. The scale affects how a number is displayed as in the following example:
display 12.3456780 to Decimal(2)

This example displays 12.35. Note that it rounds, and does not truncate, the original value.