Precision issue
Gerhard Häring
gh at ghaering.de
Fri Oct 10 05:19:23 EDT 2003
Ladvánszky Károly wrote:
> Entering 3.4 in Python yields 3.3999999999999999.
> I know it is due to the fact that 3.4 can not be precisely expressed by the
> powers of 2. Can the float handling rules of the underlying layers be set
> from Python so that 3.4 yield 3.4?
A float is a float is a float ;)
What can be done is to change the formatting of floats in print
statements, for example. IIRC there was some magic in Python to that
effect that was removed somewhere in the 2.x line.
If you're concerned about the output, why don't you just explicitely
format your float numbers? Something like:
>>> print "%.2f" % 3.4
3.40
-- Gerhard
More information about the Python-list
mailing list