too long float

Chris cwitts at gmail.com
Fri Jan 18 01:13:18 EST 2008


On Jan 18, 7:55 am, "J. Peng" <peng.... at gmail.com> wrote:
> hello,
>
> why this happened on my python?
>
> >>> a=3.9
> >>> a
>
> 3.8999999999999999
>
> I wanted 3.9 but got 3.89................
> How to avoid it? thanks.
>
> this is my python version:
>
> >>> sys.version
>
> '2.3.4 (#1, Feb  6 2006, 10:38:46) \n[GCC 3.4.5 20051201 (Red Hat 3.4.5-2)]'


>>> 3.9
3.8999999999999999
>>> 3.9 == 3.8999999999999999
True

http://effbot.org/pyfaq/why-are-floating-point-calculations-so-inaccurate.htm



More information about the Python-list mailing list