+ 1
Operations in python
Hello, I am making operations and I notice that if I make 1-273.15+273.15 it returns 1, but if I make 0.9-273.15+273.15 it doesn't return 0.9. Someone knows why that happens?
2 Antworten
+ 1
I solve it using the built-in module decimal:
for decimal import *
Decimal("0.9")-Decimal("273.15")+ Decimal("273.15")
Here is the tip for everyone having this problem as we can see here: https://docs. python.org/3/library/decimal.html
+ 4
The returned result is essentially 0.9, it's just how fractions are stored and represented. Read more about it under here:
https://en.m.wikipedia.org/wiki/Floating-point_arithmetic#Accuracy_problems