Decimal arithmatic, was Re: Python GUI app to impress the boss?

Dan Bishop danb_83 at
Fri Sep 20 21:28:44 CEST 2002

Magnus Lyckå <magnus at> wrote in message news:<3D8B1537.4010803 at>...
> ChrisBarker wrote:
> > The only reason I can see
> > to not writing your class in Python is performance, and unless you are 
> > doing a lot of calculations, that is probably a non-issue.
> Performance issues might well matter in large financial
> systems, but that's not the only reason.

Please name one other real-world situation in which decimal arithmetic
is actually *needed*.

> [snip]
> And if someone would write
> x = Decimal(9.999999999999999) - Decimal(9.9999)
> they would not get what they expected (unless they
> expected 0.000099999999998). Ok, they could write

But how often does an error of 10 parts per trillion really matter?

Afaict, not nearly enough to justify having a default number
representation that works against the hardware.

> [major snippage]

> But perhaps a command line argument or something like
> "import exact_arithmetic" could change the behaviour to
> using exact instead of floating point arithmetic. I guess
> we'd need a module anyway, to specify things. Like:
>  >>> import exact_arithmetics as exact
>  >>> exact.default_rounding(exact.UP)
>  >>> exact.default_fractions(2)
>  >>> exact.max_precision = 20
>  >>> 7.5/20
>  0.38
>  >>>

In your proposal, is 1/3 exact?  How about sqrt(2)?

What's so important about terminating decimal fractions that they
should get special treatment?  It's true that they're useful for
currency calculations, but isn't a Money class enough?

More information about the Python-list mailing list