3

Why when I'm doing this simple math subtraction I get this answer ?

In[10]: 1-0.9
Out[10]: 0.09999999999999998

someone know how to fix this ?

limitless
  • 669
  • 7
  • 18

2 Answers2

3

Refer https://docs.python.org/2/tutorial/floatingpoint.html

Use round(1-0.9, n) where it rounds the result to n decimal places

Amal Ts
  • 857
  • 1
  • 6
  • 28
0

This is a common problem with floating point precision. Usually people round when floats are displayed so the precision limitation is not shown.

David Maust
  • 8,080
  • 3
  • 32
  • 36