Comparing floats

Peter Otten __peter__ at web.de
Sun Nov 28 09:37:34 CET 2010


kj wrote:

> I understand that, in Python 2.7 and 3.x >= 3.1, when the interactive
> shell displays a float it shows "the shortest decimal fraction that
> rounds correctly back to the true binary value".  Is there a way
> to access this rounding functionality from code that must be able
> to run under version 2.6? (The idea would be to implement float
> comparison as a comparison of the rounded versions of floats.)

Doesn't float(str(x)) == x for all x imply that str(x) == str(y) if and only 
if x == y? If so, what would be the benefit of converting to string at all?




More information about the Python-list mailing list