On this page
  1. round
  2. Import & Availability
  3. Overview & Signature
  4. Usage
  5. Gotchas
  6. REPL Inspect

round

Prev: reversed | Up: __builtins__ | Next: set
Rel: abs, divmod, max, min, pow
Ref: docs.python.org — round
Tags: #public #python3 #builtins


Import & Availability

# Built-in (available globally without import)
from builtins import round

Overview & Signature

round(number, ndigits=None)

Round a number to a given precision in decimal digits.

Usage

assert round(3.14159, 2) == 3.14
assert round(2.5) == 2 and round(3.5) == 4   # banker's rounding (round half to even)
assert round(1234, -2) == 1200               # negative ndigits rounds tens/hundreds

Gotchas

REPL Inspect

help(round)

Linked from

Related notes