Monday, December 14, 2009

Dealing with float comparing in Python

Let's start.
a = 0.7
b = 0.3
a - b = 0.4
if a - b == 0.4:
print ' a - b == 0.4'
else:
print 'a - b != 0.4'

Result a - b != 0.4

OH WHAT'S...
Solution:
if str(a -b) == str(0.4):
print 'a - b == 0.4'


Read Python Doc for more information

0 comments:

Post a Comment