Floating point weirdness

Batista, Facundo FBatista at uniFON.com.ar
Wed Aug 25 11:36:24 EDT 2004


[Joshua Ginsberg]

#- >>> float('19.95')
#- 19.949999999999999
#- >>> round(19.94999999999999999, 2)
#- 19.949999999999999
#- >>> round(19.949, 1)
#- 19.899999999999999
#- 
#- Why can't I just get 19.95?

>From the Python FAQs:

	
http://www.python.org/doc/faq/general.html#why-are-floating-point-calculatio
ns-so-inaccurate

You maybe want to use Decimal (will be available in Py2.4).

If you want theory about this, you should consider reading the PEP 327:

	http://www.python.org/peps/pep-0327.html

Regards,

.	Facundo



More information about the Python-list mailing list