[Tutor] Some questions about my yen-USD.py

Andrei project5 at redrival.net
Fri Sep 8 08:46:59 CEST 2006


Pawel Kraszewski <Python <at> kraszewscy.net> writes:

> > > get me into trouble with the flakiness of float(n)? In testing I
> > > didn't find any problems, but ..
> >
> > Nah. Float accuracy is only a problem if you need around lots of
> > significant digits (16 or so).
> 
> I wouldn't bet. Such a simple thing as 0.1 can't be represented correctly on 
> Float... That's what 'decimal' is for.
> 
> See that:
> 
> >>> 0.1 + 0.1 + 0.1 - 0.3
> 5.5511151231257827e-17

For the intents and purposes of this script, this difference is of no
consequence (that value is close enough to zero):

>>> "%.2f" % (.1+.1+.1-.3)
'0.00'

Andrei




More information about the Tutor mailing list