So whenever I sum an array of floating numbers, and compare the summed number with another floating number it keeps saying they are not the same.
So the total is 1.63 The numbers are: 0.31, 0.31, 0.37, 0.33, 0.31
These numbers together makes 1.63, but whenever I compare the sum with 1.63 it says they are not the same.
How come this happens?
#!/usr/bin/python
total = 1.63
array = [ 0.31, 0.31, 0.37, 0.33, 0.31 ]
sum = 0
for n in array:
sum += float(n)
print total
print sum
if float(total) == float(sum):
print 'ok'
else:
print 'not ok'
print total, sum
result:
1.63
1.63
not ok
1.63 1.63