Serious error in int() function?
Alain Ketterlin
alain at universite-de-strasbourg.fr.invalid
Wed Apr 13 04:00:51 EDT 2016
martin.spichty at gmail.com writes:
> print int(float(2.8/0.1))
>
> yields
>
> 27
>
> instead of 28!!
That's how floating-point arithmetic works: look at the result of
2.8/0.1 to see why int() is correct.
> Is that known?
Yes, it is known, and correct since you use "float". See
http://floating-point-gui.de/ for a nice explanation. Use decimal
(https://docs.python.org/2/library/decimal.html) if you need exact
representations.
-- Alain.
More information about the Python-list
mailing list