I'm trying to compare two Decimals in Python with a tolerance of 0.01. When using Math isclose I receive False because of floating point inaccuracy. For example:
d = Decimal('123.12')
d1 = Decimal('123.11')
print(isclose(d,d1,abs_tol=0.01))
Will print out False. I know the reason for this I'm just trying to understand if there is a good way to compare Decimals in Python.
The Decimal
class implements many methods with which you can define the comparison easily as follows:
abs(d - d1) <= Decimal('0.01')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With