The round () function does not work as I expect

I am trying to use a round function here. It .5

sometimes rounds off from sometimes rounds off. So what's the problem?

Original file:

print("rounding up 0.5 is",round(.5))
print("rounding up 1.5 is",round(1.5))
print("rounding up 2.5 is",round(2.5))
print("rounding up 3.5 is",round(3.5))

      

Output:

rounding up 0.5 is 0
rounding up 1.5 is 2
rounding up 2.5 is 2
rounding up 3.5 is 4

      

+3


source to share


1 answer


From the docs :

if two multiples are equally close, rounding is done towards the even selection



So when you say rounding up

it doesn't necessarily round. It just rounds up.

+5


source







All Articles