At the coure, https://app.dataquest.io/m/200/variables-and-data-types/7/conversion-between-types, there’s an example saying round(4.5)
becomes 4, not 5. It returns 4 even at the console on the right. Shouldn’t it be 5?
Hey @guanming.kim. I believe that since we are using Python 3 in the modules, this version uses “banker’s rounding”. Banker’s rounding rounds to the nearest even number if the fractional component is halfway between two numbers. This is why 4.5 rounds to 4 and why round(5.5) returns 6.
Here’s a link for more information: https://www.learnbyexample.org/python-round-function/
Hope this helps!
1 Like
This is a very in-depth article on this issue.
Mathematically, yes, but programming isn’t mathematics.
2 Likes