Round problem | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Round problem

print(round(4.5)) print(round(3.5)) print(round(2.5)) print(round(1.5)) print(round(0.5)) print(round(-.05)) print(round(-1.5)) print(round(-2.5)) print(round(-3.5)) print(round(-4.5)) >>> 4 4 2 2 0 0 -2 -2 -4 -4 Why??? Why not 5 4 3 2 1 0 -1 -2 -3 -4 ?

27th Feb 2017, 6:43 AM
C.R.Devila
C.R.Devila - avatar
1 Answer
+ 2
It's normal, python3 and some other langs like c# use "banker's rounding" (rounding to nearest even number) instead of normal math rounding. But python2 use normal math rounding.
27th Feb 2017, 7:14 AM
Tony Loa
Tony  Loa - avatar