Skip to content
UPEEC

abs() and round()

Absolute value, and rounding to a number of digits (round-half-to-even!).

Beginner
Comments 0
abs(-3.3)        # 3.3
round(2.675, 2)  # 2.67 — 2.675 isn't exact in binary
round(0.5), round(1.5)   # 0, 2 — banker's rounding

Use the decimal module when you need exact decimal rounding.

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.