Код: Выделить всё
from decimal import Decimal, getcontext
getcontext().prec = 10
x1 = 1.1
x2 = 1.0
print( 0.1*(abs(x2 - x1)) == 0.01) ## evaluates to False. But they are mathematically equal.
print(0.1*(abs(x2 - x1)))
print(round(Decimal(0.1)*Decimal(abs(x2 - x1)),2) == 0.01) ## evaluates to False still
print(round(Decimal(0.1)*Decimal(abs(x2 - x1)),2))
print(0.01)
Подробнее здесь: https://stackoverflow.com/questions/792 ... comparison
Мобильная версия