Math errors in python

Gary Herron gherron at islandtraining.com
Sat Sep 18 13:20:12 EDT 2004


On Saturday 18 September 2004 09:50 am, Radioactive Man wrote:
> In python 2.3 (IDLE 1.0.3) running under windows 95, I get the
> following types of errors whenever I do simple arithmetic:
>
> 1st example:
> >>> 12.10 + 8.30
>
> 20.399999999999999


It's not a bug, it's a feature of binary arithmetic on ALL coumputers
in ALL languages.  (But perhaps Python is the first time it has not
been hidden from you.)

See the Python FAQ entry 1.4.2:

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


Gary Herron







More information about the Python-list mailing list