Python float - str - float weirdness
问题 >>> float(str(0.65000000000000002)) 0.65000000000000002 >>> float(str(0.47000000000000003)) 0.46999999999999997 ??? What is going on here? How do I convert 0.47000000000000003 to string and the resultant value back to float? I am using Python 2.5.4 on Windows. 回答1: str(0.47000000000000003) give '0.47' and float('0.47') can be 0.46999999999999997 . This is due to the way floating point number are represented (see this wikipedia article) Note: float(repr(0.47000000000000003)) or eval(repr(0