floating point - How does Rounding in Python work? -


i bit confused how rounding in python works.
please explain why python behaves this?

example:

>>> round(0.05,1) # makes sense 0.1 >>> round(0.15,1) # doesn't make sense! why result not 0.2? 0.1 

and same for:

>>> round(0.25,1) # makes sense 0.3 >>> round(0.35,1) # in opinion, should 0.4 evaluates 0.3 0.3 

edit: in general, there possibility python rounds down instead of rounding up. understand "abnormal" thing can happen python rounds down? or may rounded "abnormally" due how stored? (i haven't found case python rounded when expected round down)

this design. pythons' documentation:

the behavior of round() floats can surprising: example, round(2.675, 2) gives 2.67 instead of expected 2.68. this not bug: it’s result of fact decimal fractions can’t represented float.


Comments

Popular posts from this blog

how to insert data php javascript mysql with multiple array session 2 -

multithreading - Exception in Application constructor -

windows - CertCreateCertificateContext returns CRYPT_E_ASN1_BADTAG / 8009310b -