Tuesday, 27 August 2013

python incorrect rounding with decimals

python incorrect rounding with decimals

>>> a = 0.3135
>>> print("%.3f" % a)
0.314
>>> a = 0.3125
>>> print("%.3f" % a)
0.312
>>>
I am expecting 0.313 instead of 0.312 Any thought on why is this, and is
there alternative way I can use to get 0.313?
Thanks

No comments:

Post a Comment