Why not FP for Money?

Piet van Oostrum piet at cs.uu.nl
Fri Sep 24 13:46:52 CEST 2004

>>>>> Carlos Ribeiro <carribeiro at gmail.com> (CR) wrote:

CR> What should from_float do? Truncate it to 2 digits isn't possible --
CR> the fact that the literal was written with two digits was lost in the
CR> innards of the lexical analyzer long before from_float() is called.
CR> And to represent it internally as 32.719999999999999 will cause
CR> surprises for most people; but to truncate it arbitrarily is also
CR> problematic. So it was removed (that's what the release notes states,
CR> anyway)

I could use the decimal representation with the least number of digits
that, when read in as a floating-point number, gives the same value as the
argument. But that is a tricky algorithm, although it has been published.
But this algorithm would return 32.72 when you give it 32.7199999999999999
as an argument :=)
Piet van Oostrum <piet at cs.uu.nl>
URL: http://www.cs.uu.nl/~piet [PGP]
Private email: P.van.Oostrum at hccnet.nl

More information about the Python-list mailing list