Round a value up in Python by calling math.ceil(). It always returns the smallest integer greater than or equal to the input (toward +∞), which means it reliably “rounds up” for both positive and negative numbers.
Method 1: Use math.ceil for a single number
import math
print(math.ceil(4.2)) # 5
print(math.ceil(-1.2)) # -1 (toward +∞)
n = math.ceil(2.3) # int 3
Join readers who trust AllThings.How
Add us as a preferred source on Google so our practical guides show up first next time you search.
Add to Google Preferences →Method 2: Round up to N decimal places with a scale-and-ceil
Multiply to shift the decimal, apply ceil, then divide back. This pattern is quick for UI rounding or bucket thresholds.
import math
def round_up(n, decimals=0):
m = 10 ** decimals
return math.ceil(n * m) / m
print(round_up(2.341, 2)) # 2.35
print(round_up(22.45, -1)) # 30.0 (round up to tens)
Method 3: Use Decimal for exact, rule-based “round up”
For financial or compliance rules (e.g., “always round away from zero” or “toward +∞”), use Python’s Decimal, which supports precise decimal arithmetic and explicit rounding modes.
from decimal import Decimal, ROUND_UP, ROUND_CEILING
d = Decimal("2.341")
# ROUND_UP: always away from zero (2 decimals)
print(d.quantize(Decimal("0.01"), rounding=ROUND_UP)) # 2.35
# ROUND_CEILING: always toward +∞ (handles negatives differently)
print(Decimal("-2.341").quantize(Decimal("0.01"), rounding=ROUND_CEILING)) # -2.34
ROUND_UP is “away from zero”; ROUND_CEILING is “up” toward +∞, which is different for negatives.Method 4: Do integer “ceiling division” (counts, pages, batches)
When you want “how many full chunks of size b to cover a?”, use integer ceiling division. This avoids floats, conditionals, and imports.
# Works for integers; assumes positive divisor
def ceil_div(a, b):
return -(-a // b)
print(ceil_div(21, 5)) # 5
print(ceil_div(20, 5)) # 4
a and b are non‑negative, (a + b - 1) // b also works; the double‑negation form handles a wider range of integer signs cleanly.Method 5: Round up arrays with NumPy
For vectors or matrices, apply vectorized rounding with numpy.ceil() to get ceilings element‑wise.
import numpy as np
arr = np.array([3.14, 2.72, -0.1])
print(np.ceil(arr)) # [ 4. 3. -0.]
print(np.ceil(arr).astype(int)) # [ 4 3 0]
FYI: Why round() isn’t “round up”
The built‑in round() rounds half to even (banker’s rounding). That minimizes bias across many values, but it does not always round up (e.g., round(2.5) → 2). Use the methods above when you must round up by rule.
Choose math.ceil for quick single values, the scale‑and‑ceil pattern or Decimal for specific decimal places and finance rules, integer ceiling division for counts, and NumPy for arrays. That keeps your rounding explicit, predictable, and correct for the task at hand.






