123.3 + 0.1 is 123.3999999999 ?

Isaac To kkto at csis.hku.hk
Fri May 16 05:24:05 EDT 2003


>>>>> "Simon" == Simon Brunning <SBrunning at trisystems.co.uk> writes:

    Simon> In the context of monetary values, (which is what we are talking
    Simon> about, I believe) then you wouldn't expect this to sum to 1.

    Simon> £1 / 3 = £0.33. Multiply by 3, and you get £0.99. Accountants
    Simon> expect rounding errors like this. So, in a *financial* context,
    Simon> fixed point does the wrong thing, and FixedPoint works as
    Simon> expected.

I won't say that it is a "correct" thing.  Instead I'd say it is accepted
failure.  On the other hand, this is not quite as simple as what you imply.
If there are multiple number manipulations that needs to be done in a single
transaction, most accountants are trained to do the calculation to the
accuracy provided by their digital calculators (typically 10 or 12 decimal
places), and round it to the nearest cent only as the last step.  So even in
context of financial computing it isn't producing expected values to just
use fix points everywhere.  Instead, one turns numbers to fix point only as
a tool for external representation, and for auditors so that they can verify
your records without going through your internal machine representation of
numbers.  All these are done exactly the same in normal floats.

Regards,
Isaac.





More information about the Python-list mailing list