[Tutor] Money matters
Brian van den Broek
broek at cc.umanitoba.ca
Fri Jun 29 00:09:39 CEST 2007
Terry said unto the world upon 06/28/2007 02:55 PM:
> I am going to need to be handling money calculations and was wondering
> about the float problem
> in my calculations.
>
> Should I simply run the results of all calculations through something
> like this:
>
> from __future__ import division
> ...
> ...
> s=(int(round(s, 2)*100))/100
>
> Or should I be using Decimal on all money calculations?
>
> Or, is there another more preferred approach?
Hi Terry,
I'd say definitely use Decimal. Money calculations were a primary use
case for the Decimal module. (Though a bit more needs to be done to
get the right decimal precision. See
<http://www.python.org/dev/peps/pep-0327/>.)
Best,
Brian vdB
More information about the Tutor
mailing list