when i try to check whether float variable contain exact integer value i get the folowing strange behaviour. My code :
x = 1.7 print x, (x == int(x))
x += 0.1 print x, (x == int(x))
x += 0.1 print x, (x == int(x))
x += 0.1 print x, (x == int(x))
print "----------------------"
x = **2.7** print x, (x == int(x))
x += 0.1 print x, (x == int(x))
x += 0.1 print x, (x == int(x))
x += 0.1 print x, (x == int(x))
I get the folowing strange output (last line is the problem):
1.7 False
1.8 False
1.9 False
2.0 True
----------------------
2.7 False
2.8 False
2.9 False
3.0 False
Any idea why 2.0
is true
and 3.0
is false
?