Why not FP for Money?

Alex Martelli aleaxit at yahoo.com
Fri Sep 24 07:14:00 EDT 2004


Paul Rubin <http://phr.cx@NOSPAM.invalid> wrote:

> aleaxit at yahoo.com (Alex Martelli) writes:
> > yep, str(35.72) == '35.72'.
> 
> Hmm.
> 
>     >>> 35.72
>     35.719999999999999
> 
> I wonder why str(35.72) is different from repr(35.72).

Because they serve different purposes.  As the Tutorial (appendix B)
puts it, "you'll see the result you expect in the end if you simply
round the display of your final results to the number of decimal digits
you expect.  str() usually suffices".  repr is such [when feasible] that
x==eval(repr(x)), str on the other hand is expected to present a nice
display for humans, fudging things a bit for the purpose.


Alex



More information about the Python-list mailing list