Why not FP for Money?

Alex Martelli aleaxit at yahoo.com
Wed Sep 22 13:27:02 EDT 2004


Christos TZOTZIOY Georgiou <tzot at sil-tec.gr> wrote:
   ...
> >as with float: each of 'amount' and 'vat' (in Euro) has a fraction of a
> >eurocent that is less than 0.5 (about 0.4 eurocents each), and you don't
> >round them to eurocents before summing, so the total ends up with a
> >fraction of a eurocent that is _more_ than 0.5.  So the final numbers
   ...
> session, the results were correct since I had earlier issued (after
> trial and error) a
> 
> decimal.getcontext().prec=6
> 
> which I didn't include my post (forgetting about its importance).
> Hence, you are correct saying that my confidence in the Decimal type
> should not be absolute.

We do agree on this, particularly because the 'prec=6' happens to work
only depending on how many digits are in play BEFORE the decimal point.
What we'd _really_ want to specify is 'keep exactly two digits AFTER the
decimal point, no matter how many there are BEFORE', but that's not
decimal's job -- it's still a floating point type, albeit decimal, NOT a
fixed-point one.  Maybe we do need a fixed-point-decimal for 2.5...?


Alex



More information about the Python-list mailing list