-1

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?

enter image description here

Taazar
  • 1,545
  • 18
  • 27

1 Answers1

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