Get the remainder of a Decimal division in Python

You can get the remainder of a Decimal division in Python.

from decimal import Decimal, getcontext

r1 = getcontext().remainder(Decimal(10), Decimal(7))
r2 = Decimal(10) % Decimal(7)

print(r1)  # 3
print(type(r1))  # <class 'decimal.Decimal'>

print(r2)  # 3
print(type(r2))  # <class 'decimal.Decimal'>

The remainder operator is %.

Python Decimal

Python Tutorial