Skip to content
UPEEC

decimal

Exact decimal arithmetic with controllable precision and rounding — for money and billing.

Easy
Comments 0
from decimal import Decimal, ROUND_HALF_UP
Decimal("0.1") + Decimal("0.2")                        # Decimal('0.3') exactly
Decimal("2.675").quantize(Decimal("0.01"), ROUND_HALF_UP)  # 2.68

Create Decimals from strings, not floats.

Spotted a mistake or want to add detail? Suggest an improvement — Content Contributors' edits are reviewed by editors before they go live.

Discussion (0)

Sign in or join free to ask questions and discuss this topic.