As pointed out by other answers, in python they return floats probably because of historical reasons to prevent overflow problems. However, they return integers in python 3.

>>> import math
>>> type(math.floor(3.1))
<class 'int'>
>>> type(math.ceil(3.1))
<class 'int'>

You can find more information in PEP 3141.

Answer from jcollado on Stack Overflow
🌐
W3Schools
w3schools.com › python › ref_math_ceil.asp
Python math.ceil() Method
The math.ceil() method rounds a number UP to the nearest integer, if necessary, and returns the result.
🌐
Python
docs.python.org › 3 › library › math.html
math — Mathematical functions
3 weeks ago - Return the ceiling of x, the smallest integer greater than or equal to x.
Discussions

Why do Python's math.ceil() and math.floor() operations return floats instead of integers? - Stack Overflow
Ironically (as floats were used ... by floor/ceil is meaningless in the low digits because of the float representation, well before a 64 bits int would overflow. [This wasn't true in the old days of 32 bits.] ... As pointed out by other answers, in python they return floats probably because of historical reasons to prevent overflow problems. However, they return integers in python 3. >>> import math >>> ... More on stackoverflow.com
🌐 stackoverflow.com
what is the difference between using math.ceil and round for rounding the decimal ?
ceil always rounds up. More on reddit.com
🌐 r/learnpython
3
2
October 10, 2022
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 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
🌐
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
🌐
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.
🌐
VisuAlgo
visualgo.net › en › sorting
Sorting (Bubble, Selection, Insertion, Merge, Quick, Counting, Radix) - VisuAlgo
You need to already understand/remember all these: -. Logarithm and Exponentiation, e.g., log2(1024) = 10, 210 = 1024 -. Arithmetic progression, e.g., 1+2+3+4+…+10 = 10*11/2 = 55 -. Geometric progression, e.g., 1+2+4+8+..+1024 = 1*(1-211)/(1-2) = 2047 -. Linear/Quadratic/Cubic function, e.g., f1(x) = x+2, f2(x) = x2+x-1, f3(x) = x3+2x2-x+7 -. Ceiling, Floor, and Absolute function, e.g., ceil(3.1) = 4, floor(3.1) = 3, abs(-7) = 7
Find elsewhere
🌐
TikTok
tiktok.com › discover › how-to-use-math-ceil-in-python
How to Use Math Ceil in Python
3 weeks ago - Family Spring Break - TikTok GO campaign. Campaign dates are Mar 5th - 18th. Post about things to do! Up to $12,000 in rewards for creators! https://activity.tiktok.com/t/ZSud29VCP/ · Spring is here! Join TikTok Shop’s Spring Statements campaign! Post short videos of your favorite spring ...
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-math-ceil-function
math.ceil() function - Python - GeeksforGeeks
November 17, 2025 - Explanation: math.ceil(-13.1) returns -13 because it is the smallest integer greater than or equal to -13.1.
🌐
Trymito
trymito.io › excel-to-python › functions › math › CEIL
Excel to Python: CEIL Function - A Complete Guide | Mito
Math · CEIL · Related FunctionsFLOORROUND · The CEIL function in Excel rounds a number up to the nearest integer. This function is crucial in scenarios where precision to the nearest whole number is required, like in inventory management ...
🌐
Lodash
lodash.com › docs
Lodash Documentation
_.ceil · _.divide · _.floor · _.max · _.maxBy · _.mean · _.meanBy · _.min · _.minBy · _.multiply · _.round · _.subtract · _.sum · _.sumBy · _.clamp · _.inRange · _.random · _.assign · _.assignIn · _.assignInWith · _.assignWith · _.at · _.create ·
🌐
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.
🌐
Scaler
scaler.com › home › topics › python math.ceil() method
Python math.ceil() Method - Scaler Topics
November 29, 2023 - It is equivalent to the Least integer function in mathematics. Ceil in python precisely rounds up floating-point numbers to the nearest integer, which is crucial for maintaining precision in mathematical operations.
🌐
GitHub
github.com › TheAlgorithms › Python › blob › master › maths › ceil.py
Python/maths/ceil.py at master · TheAlgorithms/Python
Return the ceiling of x as an Integral. · :param x: the number · :return: the smallest integer >= x. · >>> import math · >>> all(ceil(n) == math.ceil(n) for n · ... in (1, -1, 0, -0, 1.1, -1.1, 1.0, -1.0, 1_000_000_000)) True ·
Author   TheAlgorithms
🌐
Python documentation
docs.python.org › 3 › reference › datamodel.html
3. Data model — Python 3.14.3 documentation
A built-in function object is a wrapper around a C function. Examples of built-in functions are len() and math.sin() (math is a standard built-in module). The number and type of the arguments are determined by the C function.
🌐
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.
🌐
Python Guides
pythonguides.com › ceil-function-in-python
How To Use The Ceil() Function In Python?
March 19, 2025 - The ceil function in Python is used to return the smallest integer greater than or equal to a given number. This is particularly useful in scenarios where you need to round up numbers to avoid underestimating values. The function is defined in the math module, so you need to import this module ...
🌐
Nim Programming Language
nim-lang.org
Nim Programming Language
import std/math # Basic math. assert 1 + 2 == 3 # Sum assert 4 - 1 == 3 # Subtraction assert 2 * 2 == 4 # Multiplication assert 4 / 2 == 2.0 # Division assert 4 div 2 == 2 # Integer Division assert 2 ^ 3 == 8 # Power assert 4 mod 2 == 0 # Modulo assert (2 xor 4) == 6 # XOR assert (4 shr 2) == 1 # Shift Right assert PI * 2 == TAU # PI and TAU assert sqrt(4.0) == 2.0 # Square Root assert round(3.5) == 4.0 # Round assert isPowerOfTwo(16) # Powers of Two assert floor(2.9) == 2.0 # Floor assert ceil(2.9) == 3.0 # Ceil assert cos(TAU) == 1.0 # Cosine assert gcd(12, 8) == 4 # Greatest common divisor assert trunc(1.75) == 1.0 # Truncate assert floorMod(8, 3) == 2 # Floor Modulo assert floorDiv(8, 3) == 2 # Floor Division assert hypot(4.0, 3.0) == 5.0 # Hypotenuse assert gamma(4.0) == 6.0 # Gamma function assert radToDeg(TAU) == 360.0 # Radians to Degrees assert clamp(1.4, 0.0 ..
🌐
Reddit
reddit.com › r/learnpython › how to use math.ceil in both python 2 and 3 to get the int number?
r/learnpython on Reddit: how to use math.ceil in both python 2 and 3 to get the int number?
March 21, 2018 -

in python 2, math.ceil returns float, but I need it returns int, and I also want my code run correctly in python2 and 3. Currently , I define my own ceil function like this

def ceil(float_num):
    import sys
    if sys.version[0] == '2':
        from math import ceil as ceiling
        return int(ceiling(float_num))
    elif sys.version[0] == '3':
        from math import ceil
        return ceil(float_num)

I am just wondering is there any better solution? just like from __future__ import devision?

🌐
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.