I am a bit confused about how rounding in Python works.
Could someone please explain why Python behaves like this?
Example:
>>> round(0.05,1) # this makes sense
0.1
>>> round(0.15,1) # this doesn't make sense! Why is the result not 0.2?
0.1
And same for:
>>> round(0.25,1) # this makes sense
0.3
>>> round(0.35,1) # in my opinion, should be 0.4 but evaluates to 0.3
0.3
Edit: So in general, there is a possibility that Python rounds down instead of rounding up. So am I to understand that the only "abnormal" thing that can happen is that Python rounds down? Or may it also get rounded up "abnormally" due to how it is stored? (I haven't found a case where Python rounded up when I expected it to round down)
print '%.20f %.20f %.20f'%(.15, .25, .35)
– Principlehttp://stackoverflow.com/users/8747/rob%E1%B5%A9
- some browsers such as Chrome render the escaped unicode characters in the URL bar. – Killoranround(1.25, 1)
will give1.3
, while in Python 3 it gives1.2
. – Hic