0

I want to make a script in Python that has to do some relatively simple calculation. I noticed that some very simple additions like 1.3+0.13 yield strange results (1.4300000000000002 for this example).

Is this a known issue? Is there a way to avoid it?

To test it by yourself:

print (1.3+0.13)
Anne Aunyme
  • 506
  • 4
  • 14
  • Floating point is inherently imprecise. If you're working to a known number of decimal places then scale the numbers up to avoid the point. – Mario Camilleri Jan 06 '21 at 15:11
  • You can also check the `decimal` library in python. `print(Decimal('1.3') + Decimal('.13')) >> 1.43` – g.d.d.c Jan 06 '21 at 15:55

0 Answers0