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
🌐
Note.nkmk.me
note.nkmk.me › home › python
Round Up/Down Decimals in Python: math.floor, math.ceil | note.nkmk.me
January 15, 2024 - This custom function uses abs() to get the absolute value, math.ceil() for rounding up, and math.copysign() to retain the original sign. The resulting float from math.copysign() is then converted to an integer using int(). Get the absolute value ...
🌐
Codecademy
codecademy.com › docs › python:numpy › math methods › .ceil()
Python:NumPy | Math Methods | .ceil() | Codecademy
June 13, 2025 - Yes. For negative values, it still rounds up toward zero. math.ceil() works with a single float value and returns an int.
🌐
Initial Commit
initialcommit.com › blog › python-ceiling
Python Ceiling
The ceiling function in Python is part of the math standard library. Essentially, the ceiling function always rounds decimal numbers up to the next whole number and returns an integer.
🌐
Python Tutorial
pythontutorial.net › home › advanced python › python float to int
How To Convert a Float to an Int in Python
February 20, 2021 - The ceil(x) function returns the smallest integer greater than or equal to x. For example: from math import ceil print(ceil(12.7))Code language: Python (python) ... Convert a float to an int always results in a data loss.
🌐
GeeksforGeeks
geeksforgeeks.org › python › floor-ceil-function-python
floor() and ceil() function Python - GeeksforGeeks
Python · import math x = 3.7 print(math.floor(x)) print(math.ceil(x)) Output · 3 4 · Explanation: floor(3.7) returns 3 because 3 is the greatest integer less than or equal to 3.7. ceil(3.7) returns 4 because 4 is the smallest integer greater than or equal to 3.7. math.floor(number) math.ceil(number) Parameters: number: A float or integer value.
Published   January 10, 2018
Top answer
1 of 2
15

Short answer

It was a bug. Well, not exactly a bug, but the behavior was changed based on a proposal for Python 3. Now, ceil and floor return integers (see also delnan's comment). Some details are here: http://www.afpy.org/doc/python/2.7/whatsnew/2.6.html

Why Python originally returned floats

This question has some nice answers about the behaviour before Python 3. Since the mathematical operators where wrappers around the C mathematical operators, it made sense to follow the convention of that language. Note that in C, the ceil function takes and returns a double. This makes sense because not all floats can be represented by integers (for values with a big exponent, there is no direct representation with integers).

Python was historically not explicitely designed to formally conform to some of the properties of mathematical operations (that would not happen by accident). Guido Von Rossum has acknowledged some early design mistakes and explained the rationale behind the types used in Python, notably why he preferred C types instead of reusing the ones in ABC. See for example:

  • Early Language Design and Development

  • The Problem with Integer Division. The division operator used to perform truncation when given integers or long, which was generally unexpected and error-prone: see Changing the Division Operator.

The language is supposed to evolve, though, and people tried to incorporate numeric type systems from other languages. For example, Reworking Python's Numeric Model and A Type Hierarchy for Numbers.

Why it should be an integer

The fact that integer 8 is also a real number does mean that we should return a floating point value after doing floor(8.2), exactly because we would not return a complex value with a zero imaginary part (8 is a complex number too).

This has to do with the mathematical definitions of the operations, not the possible machine representations of values: floor and ceiling mathematical functions are defined to return integers, whereas multiplication is a ring where we expect the product of x and y from set A to belong to set A too. Arguably, it would be surprising if 8.2 * 10 returned the integer 82 and not a floating point; similarly the are no good reasons for floor(8.2) to return 8.0 if we want to be conform to the mathematical meaning.

By the way, I disagree with some parts of Robert Harvey's answer.

  • There are legitimate uses to return a value of a different type depending on an input parameter, especially with mathematical operations.

  • I don't think the return type should be based on a presupposed common usage of the value and I don't see how convenient it would be. And if it was relevant, I'd probably expect to be given an integer: I generally do not combine the result of floor with a floating point.

Inconvenience of Python 3

Using the operations from C in Python could be seen as a leaky abstraction of mathematical operations, whereas Python generally tries to provide a high-level view of data-structures and functions. It can be argued that people programming in Python expect operations that just work (e.g. arbitrary precision integers) and prefer to avoid dealing with numeric types at the level of C (e.g. undefined behaviour of overflow for unsigned signed integers). That's why PEP-3141 was a sensible proposition.

However, with the resulting abstraction, there might be some cases where performance might degrade, especially if we want to take the ceiling or floor of big floats without converting them to big integers (see comment from Mark Dickinson). Some may argue that this is not a big deal if a conversion occurs because it does not impact the overall performance of your program (and this is probably true, in most cases). But unfortunately, the problem here is that the programmer cannot choose which behaviour suits the most her needs. Some languages define more expressive functions: for example Common Lisp provides fflor and fceiling, which return floating-point values. It would be preferable if Python could provide fceil too. Alternatively, a sufficiently smart compiler could detect float(math.ceil(x)) and do the right thing.

2 of 2
6

Because 8.0 is a perfectly good floating point number.

Let's generalize the concept of math.ceil to include a "digits" parameter; that is, you get to choose the number of digits after the decimal point that you want to keep. This isn't as far-fetched as it sounds; the Round function already has this ability.

By this new definition, Math.Ceil(12.755, 2) would return 12.76, which you wouldn't be able to return as an int. The only values that could be returned as int would be those of the form Math.Ceil(x, 0), but it probably doesn't make much sense to have a function that returns a different type based on the value of one of its input parameters.

Anyway, it's more convenient to stay in the floating-point realm for working with these numbers, especially since any subsequent math on the returned numbers is almost certainly going to involve floating point anyway.

Find elsewhere
🌐
datagy
datagy.io › home › python posts › python ceiling: rounding up (and python ceiling division)
Python Ceiling: Rounding Up (and Python Ceiling Division) • datagy
April 13, 2023 - The Python int() function takes a single input, typically a floating point value, and converts it to an integer. Because of this, the function can also be used to round value, but the behaviour is a bit different than expect. Let’s see what happens when we pass a positive floating point value in both the int() and the math.ceil...
🌐
STEMpedia
ai.thestempedia.com › home › python functions › math.ceil()
Learn Python math.ceil() Function | Python Programming Tutorial
June 27, 2023 - In conclusion, the Python math.ceil() function returns the ceiling of a given number. This useful function is commonly used to round a number up to its nearest integer and within financial calculations.
🌐
Scaler
scaler.com › home › topics › python math.ceil() method
Python math.ceil() Method - Scaler Topics
November 29, 2023 - As would be obvious, the ceil in python returns a single numeric int type value, irrespective of whether the input was int or float data type. The output value is the smallest integer greater than or equal to the input number.
🌐
Vultr Docs
docs.vultr.com › python › third-party › numpy › ceil
Python Numpy ceil() - Round Up Values | Vultr Docs
November 8, 2024 - The ceil() function provided by NumPy is a mathematical tool used for rounding up numerical values to the nearest integer. This function proves to be particularly useful in scenarios where precise upward rounding is necessary, such as in financial ...
🌐
GeeksforGeeks
geeksforgeeks.org › how-to-convert-float-to-int-in-python
How to convert Float to Int in Python? - GeeksforGeeks
May 10, 2025 - Example : In the below example conversion from float to int has been achieved using the floor() and ceil() methods, the former returns an int no larger than the input and the latter returns the smallest integer larger than the input.
🌐
NumPy
numpy.org › doc › 2.1 › reference › generated › numpy.ceil.html
numpy.ceil — NumPy v2.1 Manual
At locations where the condition is True, the out array will be set to the ufunc result. Elsewhere, the out array will retain its original value. Note that if an uninitialized out array is created via the default out=None, locations within it where the condition is False will remain uninitialized. ... For other keyword-only arguments, see the ufunc docs. ... The ceiling of each element in x, with float dtype.
🌐
Flexiple
flexiple.com › python › float-to-int-python
How to convert Float to int in Python? | Flexiple Tutorials | Python - Flexiple
The ‘math.ceil’ takes a floating value as a parameter and returns the smallest integer value that is greater than or equal to the argument.
🌐
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 - Coders use Python math.floor and math.ceil to return the floor or ceiling of a specific value. Learn more in this article.
🌐
Medium
medium.com › @ryan_forrester_ › converting-floats-to-integers-in-python-a-complete-guide-9ec8c994327d
Converting Floats to Integers in Python: A Complete Guide | by ryan | Medium
November 4, 2024 - Python offers several ways to convert floats to integers. Here are the main methods: # Using int() float_number = 3.7 integer_1 = int(float_number) # Result: 3 # Using round() integer_2 = round(float_number) # Result: 4 # Using math.floor() import math integer_3 = math.floor(float_number) # Result: 3 # Using math.ceil() integer_4 = math.ceil(float_number) # Result: 4 print(f"Original float: {float_number}") print(f"int(): {integer_1}") print(f"round(): {integer_2}") print(f"floor(): {integer_3}") print(f"ceil(): {integer_4}")
🌐
Board Infinity
boardinfinity.com › blog › what-is-ceil-function-in-python
What is ceil() function in Python? | Board Infinity
June 22, 2023 - In contrast, a negative number returns the number's truncated values. A single input, often a floating point number, is passed to the Python int() method, which transforms it into an integer.
🌐
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?