decimal.getcontext()
decimal.getcontext() is a Python function in the Decimal Module category. Returns the current thread-local Decimal context (precision, rounding, traps). The syntax is decimal.getcontext(). Returns: Context object. A typical example: ctx = decimal.getcontext()
ctx.prec = 50 # Set 50 significant digits
ctx.rounding = decimal.ROUND_HALF_UP. 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.localcontext(), which returns a context manager that temporarily changes the decimal precision. 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.localcontext(), 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.getcontext() immediately in the Python playground, look up unfamiliar terms in the glossary, or return to the Python Reference homepage.