In my python,you can see:
>>> 0.6+0.8
1.4
>>> 1.6+0.8
2.4000000000000004
why the result is so strange?
In my python,you can see:
>>> 0.6+0.8
1.4
>>> 1.6+0.8
2.4000000000000004
why the result is so strange?
I believe this is a problem with caluclating floats with binary rather than python,
http://docs.python.org/2/library/decimal.html explains it better than I could, in short
import decimal
num1 = decimal.Decimal("1.6")
num2 = decimal.Decimal("0.8")
num1 + num2
Writing a function to decimal your stuff for you will be easy enough.
This is because of floating point rounding error. Read basic here: http://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html
And the solution for Python for your case: http://floating-point-gui.de/languages/python/