Why 'round' function in python works like this | Sololearn: Learn to code for FREE!
Новый курс! Каждый программист должен знать генеративный ИИ!
Попробуйте бесплатный урок
+ 1

Why 'round' function in python works like this

Output of print(round(51.5)) is 52 but output of print(round(52.5)) is also 52. Does anyone knows why this kolaveri D?

19th Feb 2020, 4:02 AM
Peter Parker
Peter Parker - avatar
3 ответов
+ 3
If you want usual sense of rounding, write your own function def myRound(num) : if num % 1 == 0.5 : return num + 0.5 else : return round(num)
19th Feb 2020, 5:30 AM
Gordon
Gordon - avatar
+ 5
Banker's rounding. When summing up a large number of bank account amount, helps balance the error caused by keeping rounding up at 0.5 https://wiki.c2.com/?BankersRounding
19th Feb 2020, 4:07 AM
Gordon
Gordon - avatar
+ 1
Is there any other round function which doesn't uses bankers rounding?
19th Feb 2020, 4:20 AM
Peter Parker
Peter Parker - avatar