No, but you can use upside-down floor division:¹

def ceildiv(a, b):
    return -(a // -b)

This works because Python's division operator does floor division (unlike in C, where integer division truncates the fractional part).

Here's a demonstration:

>>> from __future__ import division     # for Python 2.x compatibility
>>> import math
>>> def ceildiv(a, b):
...     return -(a // -b)
...
>>> b = 3
>>> for a in range(-7, 8):
...     q1 = math.ceil(a / b)   # a/b is float division
...     q2 = ceildiv(a, b)
...     print("%2d/%d %2d %2d" % (a, b, q1, q2))
...
-7/3 -2 -2
-6/3 -2 -2
-5/3 -1 -1
-4/3 -1 -1
-3/3 -1 -1
-2/3  0  0
-1/3  0  0
 0/3  0  0
 1/3  1  1
 2/3  1  1
 3/3  1  1
 4/3  2  2
 5/3  2  2
 6/3  2  2
 7/3  3  3

Why this instead of math.ceil?

math.ceil(a / b) can quietly produce incorrect results, because it introduces floating-point error. For example:

>>> from __future__ import division     # Python 2.x compat
>>> import math
>>> def ceildiv(a, b):
...     return -(a // -b)
...
>>> x = 2**64
>>> y = 2**48
>>> ceildiv(x, y)
65536
>>> ceildiv(x + 1, y)
65537                       # Correct
>>> math.ceil(x / y)
65536
>>> math.ceil((x + 1) / y)
65536                       # Incorrect!

In general, it's considered good practice to avoid floating-point arithmetic altogether unless you specifically need it. Floating-point math has several tricky edge cases, which tends to introduce bugs if you're not paying close attention. It can also be computationally expensive on small/low-power devices that do not have a hardware FPU.


¹In a previous version of this answer, ceildiv was implemented as return -(-a // b) but it was changed to return -(a // -b) after commenters reported that the latter performs slightly better in benchmarks. That makes sense, because the dividend (a) is typically larger than the divisor (b). Since Python uses arbitrary-precision arithmetic to perform these calculations, computing the unary negation -a would almost always involve equal-or-more work than computing -b.

Answer from dlitz on Stack Overflow
🌐
GeeksforGeeks
geeksforgeeks.org › python › floor-ceil-function-python
floor() and ceil() function Python - GeeksforGeeks
ceil(): Rounds a number up to the nearest integer. Example: ceil() of 3.3 will be 4. Note: Both functions require importing the math module: import math
Published   January 16, 2026
🌐
Python
docs.python.org › 3 › library › math.html
math — Mathematical functions
3 weeks ago - If k is not specified or is None, ... of the arguments are negative. Added in version 3.8. ... Return the ceiling of x, the smallest integer greater than or equal to x....
Discussions

Is there a ceiling equivalent of // operator in Python? - Stack Overflow
I have decided to import ceil from math so that when one of my colleagues reads my line of code he will understand what it does! 2018-03-21T11:28:57.607Z+00:00 ... @apadana I disagree. The question asked whether there "is" an operator for this "in" Python. Based on the responses, the answer appears to be "no." I'm upvoting dlitz's answer for its usefulness, though. 2018-07-25T22:49:17.937Z+00:00 ... @SlimCheney Toss this method into a documented function ... More on stackoverflow.com
🌐 stackoverflow.com
how to use math.ceil in both python 2 and 3 to get the int number?
You can cast an int to an int, so int(math.ceil()) should return the same on 2 and 3. More on reddit.com
🌐 r/learnpython
9
1
March 21, 2018
[Python] Not able to round up despite having the Math.ceil function
Not too familiar with HTML and how the tags work there (but from what I'm guessing is the same SO thread you found, you seem to have the right idea). But if it's complaining on python's side, you could simply just do a round(float(form[nameOfInput]), 2). In this example, that will round 154.456 to 154.46. But that depends on if it's Flask that's complaining or the HTML complaining (again, I never work with HTML so I'm not sure where the complaint is coming from lol) More on reddit.com
🌐 r/learnprogramming
8
3
July 9, 2024
Python math.ceil BUG in leetcode
Did the same mistake in one of my onsites 😂. Don’t know how ceil works in python. In java we need to explicitly typecast it to double while calling ceil. 3/6 goes as integer division, math.ceil(3/6) is basically math.ceil(0), so it’s returning 0.0. While Math.ceil(3/(double)6) return 1.0. More on reddit.com
🌐 r/leetcode
6
1
January 16, 2025
🌐
W3Schools
w3schools.com › python › ref_math_ceil.asp
Python math.ceil() Method
# Import math library import math # Round a number upward to its nearest integer print(math.ceil(1.4)) print(math.ceil(5.3)) print(math.ceil(-5.3)) print(math.ceil(22.6)) print(math.ceil(10.0)) Try it Yourself »
Top answer
1 of 9
490

No, but you can use upside-down floor division:¹

def ceildiv(a, b):
    return -(a // -b)

This works because Python's division operator does floor division (unlike in C, where integer division truncates the fractional part).

Here's a demonstration:

>>> from __future__ import division     # for Python 2.x compatibility
>>> import math
>>> def ceildiv(a, b):
...     return -(a // -b)
...
>>> b = 3
>>> for a in range(-7, 8):
...     q1 = math.ceil(a / b)   # a/b is float division
...     q2 = ceildiv(a, b)
...     print("%2d/%d %2d %2d" % (a, b, q1, q2))
...
-7/3 -2 -2
-6/3 -2 -2
-5/3 -1 -1
-4/3 -1 -1
-3/3 -1 -1
-2/3  0  0
-1/3  0  0
 0/3  0  0
 1/3  1  1
 2/3  1  1
 3/3  1  1
 4/3  2  2
 5/3  2  2
 6/3  2  2
 7/3  3  3

Why this instead of math.ceil?

math.ceil(a / b) can quietly produce incorrect results, because it introduces floating-point error. For example:

>>> from __future__ import division     # Python 2.x compat
>>> import math
>>> def ceildiv(a, b):
...     return -(a // -b)
...
>>> x = 2**64
>>> y = 2**48
>>> ceildiv(x, y)
65536
>>> ceildiv(x + 1, y)
65537                       # Correct
>>> math.ceil(x / y)
65536
>>> math.ceil((x + 1) / y)
65536                       # Incorrect!

In general, it's considered good practice to avoid floating-point arithmetic altogether unless you specifically need it. Floating-point math has several tricky edge cases, which tends to introduce bugs if you're not paying close attention. It can also be computationally expensive on small/low-power devices that do not have a hardware FPU.


¹In a previous version of this answer, ceildiv was implemented as return -(-a // b) but it was changed to return -(a // -b) after commenters reported that the latter performs slightly better in benchmarks. That makes sense, because the dividend (a) is typically larger than the divisor (b). Since Python uses arbitrary-precision arithmetic to perform these calculations, computing the unary negation -a would almost always involve equal-or-more work than computing -b.

2 of 9
83

Solution 1: Convert floor to ceiling with negation

def ceiling_division(n, d):
    return -(n // -d)

Reminiscent of the Penn & Teller levitation trick, this "turns the world upside down (with negation), uses plain floor division (where the ceiling and floor have been swapped), and then turns the world right-side up (with negation again)"

Solution 2: Let divmod() do the work

def ceiling_division(n, d):
    q, r = divmod(n, d)
    return q + bool(r)

The divmod() function gives (a // b, a % b) for integers (this may be less reliable with floats due to round-off error). The step with bool(r) adds one to the quotient whenever there is a non-zero remainder.

Solution 3: Adjust the numerator before the division

def ceiling_division(n, d):
    return (n + d - 1) // d

Translate the numerator upwards so that floor division rounds down to the intended ceiling. Note, this only works for integers.

Solution 4: Convert to floats to use math.ceil()

def ceiling_division(n, d):
    return math.ceil(n / d)

The math.ceil() code is easy to understand, but it converts from ints to floats and back. This isn't very fast and it may have rounding issues. Also, it relies on Python 3 semantics where "true division" produces a float and where the ceil() function returns an integer.

🌐
Replit
replit.com › home › discover › how to use the ceil() function in python
How to use the ceil() function in Python | Replit
2 weeks ago - The solution is to import the math module and then call the function with its full prefix, math.ceil(). This explicitly tells Python where to find the function, resolving the NameError. It’s a common mistake, so always make sure you’ve imported any required modules at the top of your script, especially when adapting code from other projects.
🌐
Trymito
trymito.io › excel-to-python › functions › math › CEIL
Excel to Python: CEIL Function - A Complete Guide | Mito
The CEIL function in Excel takes a number and rounds it *up* to the nearest integer. ... Get answers from your data, not syntax errors. Download the Mito AI analyst ... Mito is the easiest way to write Excel formulas in Python.
Find elsewhere
🌐
NumPy
numpy.org › doc › 2.1 › reference › generated › numpy.ceil.html
numpy.ceil — NumPy v2.1 Manual
numpy.ceil(x, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True[, signature]) = <ufunc 'ceil'>#
🌐
STEMpedia
ai.thestempedia.com › home › python functions › math.ceil()
Learn Python math.ceil() Function | Python Programming Tutorial
June 27, 2023 - In Python, the math.ceil() function is used to return the ceiling value of a number, which means it is used to round a number up to the nearest integer that is greater than the number itself. For example, the math.ceil() of 6.3 is 7, and the math.ceil() of -10.7 is -10.
🌐
Career Karma
careerkarma.com › blog › python › python ceil and floor: a step-by-step guide
Python Ceil and Floor: A Step-By-Step Guide | Career Karma
December 1, 2023 - The Python ceil() function rounds a number up to the nearest integer, or whole number. Python floor() rounds decimals down to the nearest whole number.
🌐
Scaler
scaler.com › home › topics › python math.ceil() method
Python math.ceil() Method - Scaler Topics
November 29, 2023 - Ceil is a function defined in Python's math module which takes a numeric input and returns the integer greater than or equal to the input number.
🌐
Analytics Vidhya
analyticsvidhya.com › home › understanding floor and ceiling functions in python
Floor and Ceiling Functions in Python | Applications and Behaviour
June 20, 2023 - The floor function is handy when values need to be rounded down, like when determining the number of whole units. On the other hand, the ceil function is handy when rounding up is required, like when allocating resources or determining the minimum number of elements. Also Read: Functions 101 – Introduction to Functions in Python For Absolute Begineers
🌐
GoLinuxCloud
golinuxcloud.com › home › python › python ceil() function explained [easy examples]
Python ceil() function Explained [Easy Examples] | GoLinuxCloud
January 13, 2024 - The ceil() function, part of Python’s math module, is used for rounding a number up to the nearest integer. This function is particularly useful when you need an integer greater than or equal to a given number.
🌐
Codecademy
codecademy.com › docs › python:numpy › math methods › .ceil()
Python:NumPy | Math Methods | .ceil() | Codecademy
June 13, 2025 - The .ceil() function returns a NumPy array with the smallest integers greater than or equal to each element in x, returned as floats.
🌐
NumPy
numpy.org › doc › 2.3 › reference › generated › numpy.ceil.html
numpy.ceil — NumPy v2.3 Manual
numpy.ceil(x, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True[, signature]) = <ufunc 'ceil'>#
🌐
Kodeclik
kodeclik.com › math-ceil-in-python
Python math.ceil() function
July 15, 2025 - The math.ceil() function takes a number as input and rounds it up to the nearest integer.
🌐
Interactive Chaos
interactivechaos.com › en › python › function › mathceil
math.ceil | Interactive Chaos
The math.ceil function returns the integer closest to the argument passed that is greater than or equal to it.
🌐
NumPy
numpy.org › devdocs › reference › generated › numpy.ceil.html
numpy.ceil — NumPy v2.5.dev0 Manual
numpy.ceil(x, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True[, signature]) = <ufunc 'ceil'>#
🌐
Tutorialspoint
tutorialspoint.com › python › number_ceil.htm
Python math.ceil() Method
The Python math.ceil() method is used to find the nearest greater integer of a numeric value. For example, the ceil value of the floating-point number 3.6 is 4. The process involved is almost similar to the estimation or rounding off technique.
🌐
AskPython
askpython.com › home › round up numbers in python without math.ceil()
Round Up Numbers in Python Without math.ceil() - AskPython
June 30, 2023 - It is very easy to install and has tons of substitutions for easy switching. You can also perform permutations and combinations with this module without having to write long functions for doing so! The ceiling function is used to round up a number to it’s nearest whole number which is greater than the integer portion of that float.