The round function seems pretty tricky in python. For round(51.665,2) it shows 51.66 and for round(51.765,2) it shows 51.77. Why is it so?
Asked
Active
Viewed 79 times
-1
-
1Don't post images use text. – Sociopath Mar 09 '19 at 05:54
-
https://docs.python.org/2/library/functions.html#round. It may help you. – Ghantey Mar 09 '19 at 06:02
1 Answers
0
This is related to in binary representation of floating point numbers (numbers in base 10 are sometimes imprecisely represented in base 2). The rationale is more thoroughly described in this answer and this one. More theoretically: What causes floating point rounding errors?
Important thing to note is that Python interpreter displays rounded floating point numbers.

sophros
- 14,672
- 11
- 46
- 75
-
If the answer helped you please consider accepting it (the gray tick mark besides the up/down vote on the left of the answer). – sophros Mar 10 '19 at 15:19