Actually, it is Open Office that is "wrong" -- albeit perhaps more consistent than Excel with the fudging that both products do.
In a nutshell, the problem arises because Excel (and Open Office, I assume) represents numeric values using 64-bit binary floating-point.
The general work-around is to explicitly round calculations with decimal fractions, or whose result might have a decimal fraction, to the degree of accuracy that you expect. In this case, round 12.63-12 to 2 decimal places.
-----
In 64-bit binary floating-point, most decimal fractions cannot be represented exactly. Instead, they are approximated by the sum of 53 consecutive powers of 2 ("bits") times an exponential factor.
Moreover, the approximation of a particular decimal fraction might differ depending on the magnitude of the integer part. The integer part is represented by some of the 53 bits, leaving the sum of fewer bits to approximate the decimal fraction.
Consequently, binary computer arithmetic often results in infinitesimal differences compared to decimal arithmetic that we do on paper.
To add to the confusion, Excel formats (displays) only the first 15 significant decimal digits (rounded) that represent the binary value. Consequently, these infinitesimal differences seem to come from nowhere.
For example, 12.63 is displayed as 12.630000000000000000 when formatted with 18 decimal places; and 0.63 is displayed as 0.630000000000000000. But =12.63-12 is displayed as 0.630000000000001000.
The exact decimal representation of each binary value is:
I use period for the decimal point and comma to demarcate the first 15 significant digits.
-----
Finally, sometimes =A3-B3<=B1 does not work expected, but =A3-B3-B1 is exactly zero(!), which is 0.00E+00 when formatted as Scientific.
This is because Excel tries to compensate for the infinitesimal anomalies -- but only sometimes. In the second example, Excel replaces the actual arithmetic result with exactly zero because Excel arbitrarily deterimines that the last subtraction is "close enough" to zero.
But to demonstrate the inconsistency in this determination, note that =A3-B3-B1<=0 is FALSE(!).
In Excel (and apparently Open Office), comparison operators round the left and right expressions to 15 significant decimal digits (rounded) before comparing them. 12.63-12 rounds to 0.630000000000001, whereas 0.63 rounds to 0.630000000000000.
Bookmarks