round() Round number
Last updated: 2026-09-22
round() Round number
round(number[, ndigits]) rounds using banker's rounding; ndigits=None returns an int.
| Category | Built-in Functions |
|---|---|
| Kind | Built-in Function |
| Python Version | all |
📝 Syntax
round(number[, ndigits])
⚙️ Parameters
| number Required | The number to round (int / float). |
|---|---|
| ndigits Optional | Number of decimal places; None returns an int.(Default:None) |
Returns:An int when ndigits is None; otherwise the rounded value of the same type as number (banker's rounding).
💥 Raises
TypeError— Raised when ndigits is not an integer.OverflowError— Raised when ndigits is too large (e.g., 10**30).
▶ Example
Edit the code, press Run, and see the result in the output panel:
Output:
4
4
3.14
ℹ️ Info Python 3 uses banker's rounding to avoid long-term statistical bias.
🏷️ Related Built-in Functions
💡 Related Cases
More case studies coming soon — check back later.
❓ FAQ
QWhy is round(2.5) 2 instead of 3?
APython 3 uses banker's rounding (round half to even): an exact .5 rounds to the nearest even number, and the nearest even to 2.5 is 2; similarly round(3.5) gives 4.
QWhat does round(3.14159, 2) return?
AIt returns 3.14 — the second argument ndigits specifies the number of decimal places.
QWhat does round(123, -1) return?
AIt returns 120 — ndigits can be negative, rounding to tens, hundreds, and so on.
QIs round() exact decimal rounding?
ANo — floats have binary representation error, so round(2.675, 2) may give 2.67 rather than 2.68; for precision-sensitive values (like money) use decimal.Decimal.