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

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -