Observation
Order of operations is critical to understand why you are seeing the result:
from decimal import Decimal as D
D('0.3637') * (D('1') / D('0.9323')) == D('0.3637') / D('0.9323')
# False
(D('0.3637') * D('1')) / D('0.9323') == D('0.3637') / D('0.9323')
# True
Explanation
The reason is given here, excerpt below. Decimal arithmetic is still fundamentally finite precision.
You can and should, if it matters to you, reduce precision using getcontext().prec
. See decimal
documentation for more details.
In general decimal is probably going overboard and still will have
rounding errors in rare cases when the number does not have a finite
decimal representation (for example any fraction where the denominator
is not 1 or divisible by 2 or 5 - the factors of the decimal base
(10)).
Solution
For general comparison of floats:
What is the best way to compare floats for almost-equality in Python?