Joined: 06 Jun 2008 Posts: 8218 Location: Dubuque, Iowa, USA
Ah, the days of numerical analysis in college ... long ago yet still relevant. The decimal value 1/10 or .1 cannot be exactly represented as a floating point binary number. The computer generates the best approximation it can but the number's not going to be exact no matter what. Any time floating point is used, representation errors occur and need to be dealt with.
You can convert the value to a fixed number as CICS guy suggested (if possible -- not all floating point values can be so represented) and work with the fixed value.
If you cannot convert the value, then either rounding or truncation will be required in your coding to adjust values for the inherent imprecision of floating point.
MOVE 1 TO INCR-LOW-TO-HIGH
MOVE 30 TO INCR-HIGH-TO-LOW.
VARYING I FROM 1 BY 1
UNTIL I > 30
COMPUTE MULT-LOW-TO-HIGH = MULT-LOW-TO-HIGH *
ADD 1 TO INCR-LOW-TO-HIGH
COMPUTE MULT-HIGH-TO-LOW = MULT-HIGH-TO-LOW *
SUBTRACT 1 FROM INCR-HIGH-TO-LOW
DISPLAY 'MULT LOW TO HIGH ' MULT-LOW-TO-HIGH.
DISPLAY 'MULT HIGH TO LOW ' MULT-HIGH-TO-LOW.
which produces this output:
MULT LOW TO HIGH .26525285981219099E 33
MULT HIGH TO LOW .26525285981219102E 33
which shows that 1 times 2 times ... 29 times 30 is not the same as 30 times 29 times ... 2 times 1 on a computer.