python - Why doesn't "%0.2f" % (.3) return "0.29"? -
The IEEE 754 floating point value for 0.3 is approximately 0.29999999999999998.
Based on this, it looks like when you execute What does Python do behind the scenes to get string representation? Edit : This is interesting: In existing versions, Python displays a value based on the least decimal fraction Returns the correct binary value Rounding rounds the Python number, And 0.29 9999 is the goal of two decimal digits 0.30. "% 0.2f"% (.3) , then Python should print "0.29" But, it actually prints "0.30"
Comments
Post a Comment