Why not FP for Money?
danb_83 at yahoo.com
Fri Sep 24 19:25:13 CEST 2004
Paul Rubin <http://phr.cx@NOSPAM.invalid> wrote in message news:<7xpt4c3v3w.fsf at ruckus.brouhaha.com>...
> aleaxit at yahoo.com (Alex Martelli) writes:
> > yep, str(35.72) == '35.72'.
> >>> 35.72
> I wonder why str(35.72) is different from repr(35.72).
Because str and repr have different purposes.
repr(x) is meant to provide enough information to re-create x, so all
float values must be distinguished from each other. This requires at
least 17 significant digits, so repr(x) == '%.17g' % x.
str(x), however, is meant to return a "nice" string representation,
and so it only uses '%.12g' % x (ignoring 5 "noise" digits at the end
More information about the Python-list