I'm getting weird results in Python with a very simple operation. In my case, I'm making a funny terminal game to practice operations with fractions, and the game works fine until Python returns too much decimals. For example:
res1 =(3/4)-(6/5)
res2 = -9/20
print(res1)
print(res2)
If you operate (3/4) - (6/5) you get the result of -9/20 (in fraction). So both operations should return the same result, in decimals. However, as you can see, I get the following results:
res1 = -0.44999999999999996
res2 = -0.45
At the moment I'm using the function round()
with 2 decimals. However, I would like to know if there's a better way to fix this.