🌐
GeeksforGeeks
geeksforgeeks.org › python › floor-ceil-function-python
floor() and ceil() function Python - GeeksforGeeks
Both return an integer. Let’s take a list of floating-point numbers and apply both floor() and ceil() to each value. ... import math a = [1.1, 2.5, 3.9, 4.0, 5.8] fl = list(map(math.floor, a)) cl = list(map(math.ceil, a)) print("Floor:", fl) ...
Published   January 10, 2018
🌐
W3Schools
w3schools.com › python › ref_math_ceil.asp
Python math.ceil() Method
# Import math library import math ... integer, if necessary, and returns the result. Tip: To round a number DOWN to the nearest integer, look at the math.floor() method....
🌐
Python
docs.python.org › 3 › library › math.html
math — Mathematical functions
Return x with the fractional part removed, leaving the integer part. This rounds toward 0: trunc() is equivalent to floor() for positive x, and equivalent to ceil() for negative x.
🌐
Note.nkmk.me
note.nkmk.me › home › python
Round Up/Down Decimals in Python: math.floor, math.ceil | note.nkmk.me
January 15, 2024 - In Python, math.floor() and math.ceil() are used to round down and up floating point numbers (float). Round down (= take the floor): math.floor() Round up (= take the ceiling): math.ceil() Difference ...
🌐
Medium
medium.com › @kevingxyz › the-art-of-pythons-ceiling-and-floor-notation-684d4d354e1e
The Art of Python’s Ceiling and Floor using Operator | by Kevin | Medium
August 8, 2020 - In Python, the floor function rounds the value towards negative infinity. By playing on this principle, you will realize that by taking the negative of negative floor, can do something like this: ... In the above code, you will be getting 4. ...
Find elsewhere
🌐
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. Both of these functions are part of the math Python library.
🌐
TechGeekBuzz
techgeekbuzz.com › blog › floor-and-ceil-function-in-python
floor() and ceil() function in Python - Techgeekbuzz
From the above examples, you can ... and by using the math.floor() and math.ceil() methods, we can round down and round up every number present in the list....
🌐
Analytics Vidhya
analyticsvidhya.com › home › understanding floor and ceiling functions in python
Floor and Ceiling Functions in Python | Applications and Behaviour
June 20, 2023 - Visualizing Patterns and Trends in DataBasics of MatplotlibBasics of SeabornData Visualization with SeabornExploring Data using Python ... The floor and ceiling functions are mathematically used to round numbers to the nearest integer.
🌐
W3Schools
w3schools.com › python › ref_math_floor.asp
Python math.floor() Method
# Import math library import math ... integer, if necessary, and returns the result. Tip: To round a number UP to the nearest integer, look at the math.ceil() method....
🌐
Initial Commit
initialcommit.com › blog › python-ceiling
Python Ceiling
But we can see no matter what the decimal value of the float is, the ceil(...) function will always round to the next whole number, while the floor(...) function will always round down.
🌐
CodeRivers
coderivers.org › blog › python-math-ceil-floor
Python `math.ceil()` and `math.floor()`: A Comprehensive Guide - CodeRivers
January 23, 2025 - The math.ceil() function returns the smallest integer greater than or equal to a given number. In other words, it rounds the number up to the next highest integer. For example, if you have a number like 3.1, math.ceil() will return 4. The math.floor() function, on the other hand, returns the ...
🌐
TutorialsPoint
tutorialspoint.com › floor-and-ceil-function-python
floor() and ceil() function Python
The difference occurs when the floor value of 2.3 is 2, but the floor value of 2.9 will also be 2; unlike the estimation technique which rounds off 2.9 to 3 instead of 2. Note − This function is not accessible directly, so we need to import math module and then we need to call this function using math static object. Following is the syntax for the Python math.floor() method −
🌐
JanBask Training
janbasktraining.com › community › python-python › why-do-pythons-mathceil-and-mathfloor-operations-return-floats-instead-of-integers
Why do Python\'s math.ceil() and math.floor() operations return floats instead of integers? | JanBask Training Community
September 21, 2025 - Here are some key points to understand: Consistency in the math module: Since most math functions like sqrt(), log(), and sin() return floats, ceil() and floor() also return floats to stay uniform.
🌐
JanBask Training
janbasktraining.com › community › python-python › ceil-and-floor-equivalent-in-python-3-without-math-module
Ceil and floor equivalent in Python 3 without Math module? | JanBask Training Community
August 18, 2025 - Use // 1 for floor values since it works correctly for both positive and negative numbers. For ceil, use integer truncation plus a conditional check. These methods avoid importing math, yet give you the same results.
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.

🌐
GitHub
github.com › numpy › numpy › issues › 9068
np.ceil and np.floor are inconsistent with math.ceil and math.floor · Issue #9068 · numpy/numpy
May 7, 2017 - In Python 3, floor and ceil changed to return integers, rather than floats: >>> math.floor(1.5), math.ceil(1.5) (1, 2) >>> np.floor(1.5), np.ceil(1.5) (1.0, 2.0) # also the output for the first cas...
Author   eric-wieser