On this page
  1. decimal.Context
  2. Import
  3. Signature & Overview
  4. Methods & Attributes
  5. Usage
  6. Gotchas
  7. REPL Inspect

decimal.Context

Prev: decimal.Clamped | Up: decimal | Next: decimal.ConversionSyntax
Rel: decimal.Clamped, decimal.ConversionSyntax, decimal.Decimal, decimal.DecimalException
Ref: docs.python.org — decimal.Context
Tags: #public #python3 #stdlib #decimal


Import

import decimal
from decimal import Context

Signature & Overview

decimal.Context(prec=None, rounding=None, Emin=None, Emax=None, capitals=None, clamp=None, flags=None, traps=None)

The context affects almost all operations and controls rounding, Over/Underflow, raising of exceptions and much more. A new context can be constructed as follows:

Methods & Attributes

Usage

from decimal import Context, Decimal

ctx = Context(prec=6)
assert str(ctx.divide(Decimal(1), Decimal(3))) == "0.333333"

Gotchas

REPL Inspect

from decimal import Context
help(Context)

Linked from

Related notes