string - Python float - str - float weirdness -
>>> float(str(0.65000000000000002))  0.65000000000000002  >>> float(str(0.47000000000000003))  0.46999999999999997     ???   what going on here? how convert 0.47000000000000003 string , resultant value float?
i using python 2.5.4 on windows.
str(0.47000000000000003) give '0.47' , float('0.47') can 0.46999999999999997.  due way floating point number represented (see wikipedia article)
note: float(repr(0.47000000000000003)) or eval(repr(0.47000000000000003)) give expected result, should use decimal if need precision.
Comments
Post a Comment