You might consider this question as a duplicate of Python Rounding Inconsistently.
However I still think that there is a justification to emphasise this Python behaviour with it.
While using Python to prepare test data for a C program, I have found this strange behaviour of Python. The rounding of 'halves' come out in pairs!
Can anybody please provide an explanation?
Positive:
>>> round (0.5)
0
>>> round (1.5)
2
>>> round (2.5)
2
>>> round (3.5)
4
>>> round (4.5)
4
>>> round (5.5)
6
>>> round (6.5)
6
Negative:
>>> round(-0.5)
0
>>> round(-1.5)
-2
>>> round(-2.5)
-2
>>> round(-3.5)
-4
>>> round(-4.5)
-4
>>> round(-5.5)
-6
>>> round(-6.5)
-6
>>> round(-7.5)
-8
>>> round(-8.5)
-8