Why Is Rounding 0.5 (decimal) Not Exact?
One half, i.e. 0.5 in decimal, has an exact binary representation: 0.1 Nevertheless, if I round it to integer, I get 0 instead of 1. I tried in Python and C, which behave the same.
Solution 1:
I know they changed the round method in python 3.
So, under v2.7.3:
In[85]: round(2.5)
Out[85]: 3.0In[86]: round(3.5)
Out[86]: 4.0
under v3.2.3:
In[32]: round(2.5)
Out[32]: 2In[33]: round(3.5)
Out[33]: 4
I don't know if it helps you but I am posting it as answer since I can't comment due to my low reputation.
The question is answered more properly here : Python 3.x rounding behavior
Post a Comment for "Why Is Rounding 0.5 (decimal) Not Exact?"