floating point arithmetic

John Machin sjmachin at lexicon.net
Tue Aug 26 17:23:12 EDT 2008


On Aug 27, 7:11 am, fred8865 <xtd8... at gmail.com> wrote:

> I understand that due to different arithmetic used in floating points
> they are just approximations. Hence, 180/100=1 in my python interpreter.

It's not "hence". What you are seeing is truncating integer division.

> How can I tackle this problem of inaccurate floating point numbers?

>>> 180 / 100
1
>>> 180 / 100.
1.8
>>> 180 / float(100)
1.8
>>> from __future__ import division
>>> 180 / 100
1.8



More information about the Python-list mailing list