0

When trying to add or multiply certain values, double conversion generates incorrect results.

>0.1 + 0.2
> > 0.30000000000000004

> 0.1 * 0.1
> > 0.010000000000000002

Is there any fix for this other than repetitive round() statements? Thanks!

eyllanesc
  • 235,170
  • 19
  • 170
  • 241
yuwe
  • 167
  • 1
  • 13
  • Note that Python docs are pretty comprehensive on this as well https://docs.python.org/3/tutorial/floatingpoint.html – Grismar Jan 29 '20 at 00:51
  • And finally, there's solutions to some of your problems if you're willing to make the effort to use them (but there's limitations of course) https://docs.python.org/3.7/library/fractions.html – Grismar Jan 29 '20 at 00:52

0 Answers0