How to compare floating point values in Python

1 Answer

0 votes
from decimal import Decimal

result = Decimal('0.1') + Decimal('0.1') + Decimal('0.1')

print(Decimal('0.3') == result)

print(float(result) == 0.3)



'''
run:

True
True

'''

 



answered Jul 10, 2023 by avibootz
...