decimal.localcontext()
decimal.localcontext() is a Python function in the Decimal Module category. Returns a context manager that temporarily changes the decimal precision. The syntax is decimal.localcontext(ctx=None). Returns: Context manager. A typical example: with decimal.localcontext() as ctx:
ctx.prec = 30
# High precision operations here
# Original precision restored. A close sibling is decimal.Decimal(), which creates a Decimal number from a string, integer, or float. Provides exact decimal arithmetic. A close sibling is decimal.getcontext(), which returns the current thread-local Decimal context (precision, rounding, traps). A close sibling is decimal.Decimal.quantize(), which rounds a Decimal to the given exponent (for currency formatting). More about this category: Decimal fixed-point arithmetic — Decimal, getcontext, quantize. Related Decimal Module entries: decimal.Decimal(), decimal.getcontext(), decimal.Decimal.quantize(). This page is part of the free Python Reference documentation covering 978+ functions, methods, and modules with examples and parameter details. You can try decimal.localcontext() immediately in the Python playground, look up unfamiliar terms in the glossary, or return to the Python Reference homepage.