1

I am trying to understand the decimal rounding behavior in python. What I find strange is the following:

1) Multiplying 70 by 11.46950 gives me 802.865

2) Multiplying 70 by 11.46750 gives me 802.7249999999999

Why is there extra precision in the second case and not the first case? I understand that internally, the decimal cannot be represented exactly. But that reason should also apply to the first case as well?

I am using python3.6.

Thanks

pokiman
  • 956
  • 2
  • 12
  • 20
  • Try printing with more digits, eg `print(format(70 * 11.46750, '.50f'))` – PM 2Ring Apr 28 '18 at 12:28
  • Does the info here help? https://stackoverflow.com/questions/20473968/floating-point-numbers Basically, the result of `70 * 11.46950` is slightly over 802.865 and the result of `70 * 11.46950` is slightly under 802.725 – PM 2Ring Apr 28 '18 at 12:38
  • Yes it did. thanks – pokiman May 13 '18 at 20:02

0 Answers0