Decimal fixed-point data

The data attributes for declaring decimal fixed-point variables are DECIMAL and FIXED.

For example, the following DECLARE statement specifies that A represents decimal fixed-point data of 5 digits, 4 of which are to the right of the decimal point.

  declare A fixed decimal (5,4);

These two examples both specify that B represents integers of 7 digits:

  declare B fixed (7,0) decimal;
  declare B fixed decimal(7);

The following example specifies that C has a scaling factor of -2. This means that C holds 7 digits in the range -9999999*100 - 9999999*100, in increments of 100.

  declare C fixed (7,-2) decimal;

The following example specifies that D represents fixed-point data of 3 digits, 2 of which are fractional.

  declare D decimal fixed real(3,2);

Decimal fixed-point data is stored two digits per byte, with a sign indication in the rightmost 4 bits of the rightmost byte. Consequently, a decimal fixed-point data item is always stored as an odd number of digits, even though the declaration of the variable can specify the number of digits, p, as an even number.

When the declaration specifies an even number of digits, the extra digit place is in the high-order position, and it participates in any operation performed upon the data item, such as in a comparison operation. If the extra high-order digit place is nonzero, the use of the data in arithmetic operation or assignment may produce an exception. Any arithmetic overflow or assignment into an extra high-order digit place can be detected only if the SIZE condition is enabled.