decimal
Stdlib — MathPython 2.0+Beginner
Arbitrary-precision decimal floating-point arithmetic
Quick Info
- Documentation
- Official Docs
- Python Version
- 2.0+
- Dependencies
- None — Python Standard Library
- Install
Included with Python
Learn by Difficulty
Quick Example
python
from decimal import Decimal, getcontext # Precise decimal arithmetic print(0.1 + 0.2) # Float imprecision print(Decimal("0.1") + Decimal("0.2")) # Exact getcontext().prec = 50 pi = Decimal("3.14159265358979323846264338327950288419716939937510") print(f"Pi to 50 digits: {pi}")
The decimal module is part of Python's standard library. Arbitrary-precision decimal floating-point arithmetic.
Try in PlaygroundTags
stdlibmathnumeric