Numerical Standard Library Modules

decimal — standard library module

Decimal floating-point arithmetic with configurable precision, rounding and traps. Construct Decimal values from strings to avoid importing binary float approximation; arithmetic is subject to the context.

Formal Syntax & Structure

python syntaxpython
import decimal

Return Value

Not applicable

Import binds a module name; individual APIs determine results.

Working Example

Example Snippetpython
from decimal import Decimal, localcontextwith localcontext() as ctx:    ctx.prec = 4    print(Decimal("1") / Decimal("3"))
Python Reference