Dick Moores wrote:

>>  >>> print round(2.1345, 3)
>> 2.135
> 
> But now I have a question.
> 
>  >>> print "%.3f" % 22.1345
> 22.134
> 
> Why the 22.134's?

Because neither 2.1345 nor 22.1345 can be represented exactly in 
floating point, and the errors are in the opposite direction:

In [4]: repr(22.1345)
Out[4]: '22.134499999999999'
In [5]: repr(2.1345)
Out[5]: '2.1345000000000001'

Kent
_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to