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 "% 0.2f"% (.3) , then Python should print "0.29" But, it actually prints "0.30"

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.

Comments

Popular posts from this blog

Verilog Error: output or inout port "Q" must be connected to a structural net expression -

jasper reports - How to center align barcode using jasperreports and barcode4j -

c# - ASP.NET MVC - Attaching an entity of type 'MODELNAME' failed because another entity of the same type already has the same primary key value -