RE: prePEP: Decimal data type

From: Alex Martelli (aleax_at_aleax.it)
Date: 11/06/03


Date: Thu, 06 Nov 2003 08:22:15 GMT

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



Relevant Pages

  • Re: XQ and ->Qpi bug on large X
    ... you shouldn't be rounding to only two digits ... I am trying to make a similar point here about rounding; ... and round it, ... prior to using the input values in calculations. ...
    (comp.sys.hp48)
  • enthusiasm in relation to physical start
    ... carefully deserts. ... accounting off a ethnic sir. ... tree will round but the slim desert. ... GiGi's space with capacitys, it'll sufficiently entertain the ...
    (sci.crypt)
  • Re: My Completed RATECRYPT() function included below
    ... I was interested because most rounding functions do not round in an unbiased manner. ... I have seen various reports of clipper rounding problems but there are many different rounding methods and clipper chose a common one. ... The gaussian method (an unbiased estimator) gives the same answer you would get using a standard c compiler and printed with printf. ...
    (comp.lang.clipper)
  • Re: XQ and ->Qpi bug on large X
    ... plot of all specific values resembling a "normal distribution" ... we should round each value ... which fails if we start computing "mean square" ... the moment we begin rounding data, we make the data less reliable ...
    (comp.sys.hp48)
  • Re: Mike W. Corner
    ... tender and will round up in half-a-heartbeat, you can spin them out. ... Rounding up is one of your two primary defenses against a broach. ... Having a plan sure helps. ...
    (rec.motorcycles.dirt)