Using python 3.4.3,
round(5/2) # 2
Shouldn't it return 3?
I tried using python 2 and it gave me the correct result
round(5.0/2) # 3
How can I achieve a correct rounding of floats?
if two multiples are equally close, rounding is done toward the even choice (so, for example, both round(0.5) and round(-0.5) are 0, and round(1.5) is 2).
Quoting the documentation for the round
function.
Hope this helps :)
On a side note, I would suggest always read the doc when you face this kind of question (haha)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With