Why So ?
>>> round(2/3)
0.0
>>> round(0.66666666666666666666666666666667)
1.0
>>> round(2.0/3)
1.0
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
That’s not strange behaviour from
round():Try this:
Using
/with two integer values will do an integer division. So the argument toround()is already 0, which makesround()return 0.Update: as @Mark noted in the comment, this behaviour changed in Python 3:
2/3will do a floating point division as2.0/3does in Python 2.2//3can be used to get integer division behaviour on both versions).Your last example works, because
2.0is not integer, so2.0/3will do a “propper” floating point division: