I have looked up online regarding python's floating point arithmetic limitation and seems like the easiest way to solve the problem is to use decimal module. For instance, I tried the below code and it gave me the perfect 0.8 answer.
from decimal import Decimal
Decimal('4') - Decimal('3.2')
However, when I try to incorporate this method into an arithmetic that involves list, the method failed.
from decimal import Decimal
number = [3.2, 1.1]
Decimal('4') - Decimal('number[0]')
This gives me an "InvalidOperation" error. Then I tried
from decimal import Decimal
number = [3.2, 1.1]
Decimal('4') - Decimal(number[0])
This compiles but gives me Decimal('0.7999999999999998223643160600') instead of 0.8
So can anyone please tell me how to solve such a problem? (either use Decimal or any other methods).
Thanks in advance!