If x is a float number that you want to round up to an integer, and you want an integer type result, you could use

rounded_up_x = int(-(-x // 1))

This works because integer division by one rounds down, but using the negative sign before and after doing the division rounds the opposite direction. The int here converts the float result to an integer. Remove that int if you want a floating point value that equals an integer, which is what some programming languages do.

Hat-tip to @D.LaRocque for pointing out that Python's ceil() function returns an integer type.

Answer from Rory Daulton on Stack Overflow
🌐
Reddit
reddit.com › r/learnpython › how to round up without math modules?
How to round up without math modules? : r/learnpython
August 24, 2021 - Subreddit for posting questions and asking for general advice about all topics related to learning python. ... Sorry, this post was deleted by the person who originally posted it. Share ... Casting a float as an integer will always round down, you can make use of that to create your own 'roundup' ...
🌐
AskPython
askpython.com › home › round up numbers in python without math.ceil()
Round Up Numbers in Python Without math.ceil() - AskPython
June 30, 2023 - math.floor(your_number): It works as the flooring function for a particular number. It rounds your number down to the integer less than itself.
🌐
Sololearn
sololearn.com › en › Discuss › 2741701 › round-up-and-round-down-without-ceil-and-floor
Round up and round Down without ceil and floor? | Sololearn: Learn to code for FREE!
Some solutions without import math? https://code.sololearn.com/cheV1liq5384/?ref=app · python · 31st Mar 2021, 2:47 PM · Илья Мирошник · 2 Answers · Answer · + 3 · Looks like a solution, so what is your question? It has one flaw though: it doesn't work if the number has less decimal places than specified by grade.
🌐
Medium
medium.com › @ElizavetaGorelova › rounding-in-python-choosing-the-best-way-c20c2a37fe29
Rounding in Python: Choosing The Best Way | by Elizaveta Gorelova | Medium
March 15, 2024 - Note: In Python 3, math.ceil returns an integer, while in Python 2 it returns a float. To round down, use the floor() function.
🌐
Sololearn
sololearn.com › en › Discuss › 3103388 › how-do-i-round-up-the-the-nearest-whole-number-without-importing-math-thanks
how do i round up the the nearest whole number without importing math. Thanks | Sololearn: Learn to code for FREE!
Mr Steven Kervick🇺🇦 there is a way to get the smallest floating point number, which is called epsilon. Use that to add *almost* 1.0, but just enough under 1.0 that it won't round up an exact integer. import sys rup = 1.0 - sys.float_info.epsilon ... y = int(y + rup) # to round up
🌐
Codingzap
codingzap.com › home › blog – programming & coding articles › methods to perform python round down: floating point numbers
Methods to Perform Python Round Down: Floating Point Numbers
March 12, 2025 - We can use the Floor Method or specifically Math Floor Method for the Negative Numbers as well. If we use the Math Floor Method for Negative Numbers, it will not prompt any kind of errors or warning messages.
Find elsewhere
🌐
FavTutor
favtutor.com › blogs › round-down-python
Round Down Numbers in Python (With Examples and Code)
September 3, 2022 - Rounding is the practice of simplifying a number without modifying much of its value. For instance, 9.8 rounded to 10, with only a 0.2 difference. Likewise, 10.2 rounded to 10, with the same difference. So the only goal is to get a value that is close to the original value but in a simpler form. Let's dive deeper into rounding down in Python!
🌐
Python Pool
pythonpool.com › home › blog › best ways to round down numbers in python
Best Ways to Round Down Numbers in Python - Python Pool
January 1, 2024 - We will discuss 5 other methods to round down a number in Python, except the round() method. As the name suggests, truncation is used to shorten things. It is a straightforward method that can be used to round a number by truncating a given number of digits. ... In this example, we have used inbuilt math...
🌐
GeeksforGeeks
geeksforgeeks.org › python › how-to-round-numbers-in-python
How to Round Numbers in Python? - GeeksforGeeks
July 15, 2025 - floor(x) always rounds down, even for negative numbers. If we want to round up to a specified decimal place, you can combine multiplication, math.ceil(), and division. python ·
🌐
Real Python
realpython.com › python-rounding
How to Round Numbers in Python – Real Python
December 7, 2024 - Only a familiarity with the fundamentals of Python is necessary, and the math should feel familiar if you’ve had high school algebra. You’ll start by looking at Python’s built-in rounding mechanism. Take the Quiz: Test your knowledge with our interactive “Rounding Numbers in Python” quiz. You’ll receive a score upon completion to help you track your learning progress: ... Test your knowledge of rounding numbers in Python. Get Your Code: Click here to download the free sample code you’ll use to learn about rounding numbers in Python.
🌐
Raspberry Pi Forums
forums.raspberrypi.com › board index › programming › python
In Python 3 without the Math package, what is the equivalent of ceiling and floor? - Raspberry Pi Forums
Mathematica · High Altitude Balloon · Weather station · Programming · C/C++ Java · Python · Scratch · Other programming languages · Windows 10 for IoT · Wolfram Language · Bare metal, Assembly language · Graphics programming · OpenGLES · OpenVG ·
🌐
freeCodeCamp
freecodecamp.org › news › how-to-round-numbers-up-or-down-in-python
Python Round to Int – How to Round Up or Round Down to the Nearest Whole Number
May 24, 2022 - When working with float values ... up or down, or to the nearest whole number. In this article, we'll see some built-in functionalities that let us round numbers in Python. And we'll see how to use them with some examples. We'll start with the round() function. By default, it rounds a number to the nearest whole number. We'll also see how to use the function's parameters to change the type of result returned to us. We'll then talk about the math.ceil() and ...
🌐
Altcademy
altcademy.com › blog › how-to-round-down-in-python
How to round down in Python
June 13, 2023 - In mathematics and computer programming, rounding is the process of adjusting a fractional number to make it as close as possible to a whole number. Rounding down, also known as "flooring" a number, is the process of rounding a number down to the nearest whole number. In this blog post, we will explore how to round down numbers in Python...
🌐
Replit
replit.com › home › discover › how to round up in python
How to round up in Python
First, negating the numerator (-n) ... to round down toward a more negative number. For example, -10 // 3 results in -4 instead of -3. The final negation flips the sign back, effectively rounding the original division up to the next whole number.
🌐
Python.org
discuss.python.org › python help
Trying to understand rounding - in python - - Python Help - Discussions on Python.org
June 17, 2023 - hello @all, I’m new here, pls. be tolerant if I harm habits I don’t know about, I’m working on bin-FP-math imprecisions, and was pointed by Steven D’Aprano that python is doing a good job - from a decimal POV - in rounding >>> round(0.30000000000000004, 16) 0.3 https://mail.gnome.org/archives/gnumeric-list/2021-July/msg00019.html ( where standard FP algorithms fail to 0.3000000000000001 reg. scaling up =0.30000000000000004 by 10^16 → 3000000000000000.5 ) searching in the forum I found th...
Top answer
1 of 6
26

You can us either int(), math.trunc(), or math.floor(). They all will do what you want for positive numbers:

>>> import math
>>> math.floor(12.6)  # returns 12.0 in Python 2
12   
>>> int(12.6)
12
>>> math.trunc(12.6)
12

However, note that they behave differently with negative numbers: int and math.trunc will go to 0, whereas math.floor always floors downwards:

>>> import math
>>> math.floor(-12.6)  # returns -13.0 in Python 2
-13
>>> int(-12.6)
-12
>>> math.trunc(-12.6)
-12

Note that math.floor and math.ceil used to return floats in Python 2.

Also note that int and math.trunc will both (at first glance) appear to do the same thing, though their exact semantics differ. In short: int is for general/type conversion and math.trunc is specifically for numeric types (and will help make your intent more clear).

Use int if you don't really care about the difference, if you want to convert strings, or if you don't want to import a library. Use trunc if you want to be absolutely unambiguous about what you mean or if you want to ensure your code works correctly for non-builtin types.

More info below:


Math.floor() in Python 2 vs Python 3

Note that math.floor (and math.ceil) were changed slightly from Python 2 to Python 3 -- in Python 2, both functions will return a float instead of an int. This was changed in Python 3 so that both methods return an int (more specifically, they call the __float__ method on whatever object they were given). So then, if you're using Python 2, or would like your code to maintain compatibility between the two versions, it would generally be safe to do int(math.floor(...)).

For more information about why this change was made + about the potential pitfalls of doing int(math.floor(...)) in Python 2, see Why do Python's math.ceil() and math.floor() operations return floats instead of integers?

int vs math.trunc()

At first glance, the int() and math.trunc() methods will appear to be identical. The primary differences are:

  • int(...)
    • The int function will accept floats, strings, and ints.
    • Running int(param) will call the param.__int__() method in order to perform the conversion (and then will try calling __trunc__ if __int__ is undefined)
    • The __int__ magic method was not always unambiguously defined -- for some period of time, it turned out that the exact semantics and rules of how __int__ should work were largely left up to the implementing class.
    • The int function is meant to be used when you want to convert a general object into an int. It's a type conversion method. For example, you can convert strings to ints by doing int("42") (or do things like change of base: int("AF", 16) -> 175).
  • math.trunc(...)
    • The trunc will only accept numeric types (ints, floats, etc)
    • Running math.trunc(param) function will call the param.__trunc__() method in order to perform the conversion
    • The exact behavior and semantics of the __trunc__ magic method was precisely defined in PEP 3141 (and more specifically in the Changes to operations and __magic__ methods section).
    • The math.trunc function is meant to be used when you want to take an existing real number and specifically truncate and remove its decimals to produce an integral type. This means that unlike int, math.trunc is a purely numeric operation.

All that said, it turns out all of Python's built-in types will behave exactly the same whether you use int or trunc. This means that if all you're doing is using regular ints, floats, fractions, and decimals, you're free to use either int or trunc.

However, if you want to be very precise about what exactly your intent is (ie if you want to make it absolutely clear whether you're flooring or truncating), or if you're working with custom numeric types that have different implementations for __int__ and __trunc__, then it would probably be best to use math.trunc.

You can also find more information and debate about this topic on Python's developer mailing list.

2 of 6
3

you can do this easily with a built in python functions, just use two forward slashes and divide by 1.

>>> print 12.75//1
12.0
>>> print 1.999999999//1
1.0
>>> print 2.65//1
2.0