prePEP: Decimal data type

Alex Martelli aleax at aleax.it
Thu Nov 6 09:22:15 CET 2003


Tim Peters wrote:
   ...
> You do need to explicitly round (if desired) after * and /.  Because of
> the high value attached to 100% conformance to imposed standards in
> accounting apps, I think it's a good thing that you're forced to round
> explicitly when the result of a calculation can't be represented exactly
> in the mandated format -- those are exactly the places where your app will
> fail to meet the requirements, so it's good to be aware of them.

European Union directives (adopted as laws by member states) mandate
the rounding procedure to be used in computations involving Euros (round
to closest Eurocent, always round up on half-Eurocent results); they very
explicitly mention that this may give a 1-Eurocent discrepancy compared
to "exact" arithmetic, and give examples; they establish that such a 1-cent
discrepancy that comes from following exactly the prescribed rules is NOT
legal cause for any lawsuit whatsoever; they earnestly recommend that all
computing equipment and programs follow these same rules to avoid the huge
headaches that would result in trying to reconcile accounts otherwise.

Thus, for most accounting programs intended to run within the EU (not just
in Euros: these provisions also apply to the other non-Euro currencies, as
far as EU law is concerned), I do NOT think it would be a good thing for
the programmer to have to remember to round explicitly -- the legal mandate
is about rounding rules and it's quite easy to avoid the "fail to meet the
requirements", as they seem designed to be easy to meet.

Whether Decimal itself allows an optional rounding-policy (including of
course "no rounding" as a possibility) is one issue (I guess that might
violate some ANSI or IEEE standard...?) but I most surely do want to be
able to use such policies in whatever arithmetic type underlies Money --
so I hope Decimal is at least designed so that _subclasses_ can easily
provide such customized rounding (e.g., feature-testing for a __round__
specialmethod, not defined in the baseclass Decimal if need be, but
offering the needed hook for subclasses to add the functionality).


Alex





More information about the Python-list mailing list