all Python 3Exceptionsexception
decimal.Inexact
module exceptions
Decimal rounding discarded non-zero digits (the result is inexact).
Syntax
raise decimal.Inexact
The trap is disabled by default: the signal just sets a flag in context.flags while the rounded result is returned as usual. You turn it on when you need to know that digits were actually lost, say that an amount did not divide evenly. Do not confuse it with Rounded, which fires whenever digits are dropped at all, even zeros; Inexact fires only when the discarded digits were non-zero.
Examples
import decimal
try:
raise decimal.Inexact
except decimal.Inexact as e:
print(type(e).__name__) # → Inexact
See also
Open in the full glossarydocs.python.orgReport an inaccuracy