The math.ceil (ceiling) function returns the smallest integer higher or equal to x.

For Python 3:

import math
print(math.ceil(4.2))

For Python 2:

import math
print(int(math.ceil(4.2)))
Answer from Steve Tjoa on Stack Overflow
๐ŸŒ
DataCamp
datacamp.com โ€บ tutorial โ€บ python-round-up
How to Round Up a Number in Python | DataCamp
July 22, 2024 - Discover three techniques to round up numbers in Python: using Python round up methods like math.ceil() from the math module, the decimal module, and NumPy.
๐ŸŒ
Real Python
realpython.com โ€บ python-rounding
How to Round Numbers in Python โ€“ Real Python
December 7, 2024 - So, round() rounds 1.5 up to 2, and 2.5 down to 2! Before you go raising an issue on the Python bug tracker, rest assured you that round(2.5) is supposed to return 2.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ how-to-round-numbers-in-python
How to Round Numbers in Python? - GeeksforGeeks
July 15, 2025 - Pythonโ€™s math module provides ... ... If we want to round up to a specified decimal place, you can combine multiplication, math.ceil(), and division....
๐ŸŒ
Replit
replit.com โ€บ home โ€บ discover โ€บ how to round up in python
How to round up in Python
Python provides several functions, like math.ceil(), to accomplish this with precision for various applications. You'll learn different techniques and see real world examples. You will also get practical tips and advice to debug common problems. import math number = 4.2 rounded_up = math.ceil(number) print(rounded_up)--OUTPUT--5
๐ŸŒ
Python.org
discuss.python.org โ€บ python help
Integer division - Python Help - Discussions on Python.org
January 25, 2023 - What is the result of this code: print(6 // 0.4) I thought the answer is 15.0 but I am getting 14.0. Any explanation for this answer I will appreciate.
๐ŸŒ
Delft Stack
delftstack.com โ€บ home โ€บ howto โ€บ python โ€บ python round up
How to Round Up a Number in Python | Delft Stack
February 2, 2024 - An example code is given below to explain how to use simple arithmetic to round up a number in Python without importing the math library. n = 22 div = 5 print(int(n / div) + (n % div > 0)) ... The symbol for the floor division operator is //. It ...
Find elsewhere
๐ŸŒ
GoLinuxCloud
golinuxcloud.com โ€บ home โ€บ python โ€บ python round up practical examples [5 methods]
Python round up practical examples [5 Methods] | GoLinuxCloud
November 16, 2021 - See the example below: ... import math # defining a number num1 = 43.0 num2 = 10 # Python round up division print("Rounded using round method:", round(num1/num2)) print("Rounded using math.ceil method: ", math.ceil(num1/num2))
๐ŸŒ
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 - 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 math.floor() methods which rounds up and rounds down a number to the nearest whole number/integer respectively.
๐ŸŒ
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 - Learn how to use the Python ceiling function to round numbers up. Learn differences between Python 2 and 3 and how ceiling division works.
๐ŸŒ
Squash
squash.io โ€บ how-to-round-up-a-number-in-python
How to Round Up a Number in Python
We then use the negation operator (-) twice to round up the number. By negating the result of the division and then negating it again, we effectively round up the number to the nearest integer.
๐ŸŒ
LearnDataSci
learndatasci.com โ€บ solutions โ€บ python-double-slash-operator-floor-division
Python Double Slash (//) Operator: Floor Division โ€“ LearnDataSci
In Python, we can perform floor division (also sometimes known as integer division) using the // operator. This operator will divide the first argument by the second and round the result down to the nearest whole number, making it equivalent to the math.floor() function.
๐ŸŒ
Inspector
inspector.dev โ€บ home โ€บ round up numbers to integer in python โ€“ fast tips
Round Up Numbers to Integer in Python - Inspector.dev
June 17, 2025 - The math library in Python provides the ceil() and floor() functions to round numbers up and down, respectively, to the nearest integer. These functions are useful when you need to work with integer values, especially in cases like calculating ...
๐ŸŒ
Reddit
reddit.com โ€บ r/learnpython โ€บ does the double slash (or floor division i believe) operator round numbers ending in .4 up?
r/learnpython on Reddit: Does the double slash (or floor division I believe) operator round numbers ending in .4 up?
May 26, 2022 -

I'm taking my first programming course in college this semester and we've been tasked with a few basic exercises using mostly if-else statements and the odd very basic for loop. For this particular exercise, one issue I've come with that I hadn't before is when using the // operator. From my understanding + research and what has been taught to me, this operator is supposed to simply round down to the nearest whole number. I won't explain the entire exercise/project's goal, as per the rules of the subreddit, but the specific case I've just observed is when rounding -2.4, or more specifically abs(-2.4). I defined a variable as such:

digit1 = abs(num // 10)

num is a previously defined variable containing an integer input ( int(input("")) ). This variable is used to look for the first digit of the inputted number. When I input -24, the result I expected was 2, but the output ended up being 3. I'm not too sure what's going on. Is the absolute function or the fact that it's a negative number affecting the result?

Also, in case this is relevant, we're using replit as an IDE.

Thanks in advance for any responses.

Sidenote: I apologize if this is a very simple issue that I'm just not seeing. Asked similar questions in other sites and people seemed annoyed at how simple the solution was. Reddit's always been pretty nice but hey, you never know.

๐ŸŒ
Finxter
blog.finxter.com โ€บ home โ€บ learn python blog โ€บ how to round a number up in python?
How to Round a Number Up in Python? - Be on the Right Side of Change
April 22, 2022 - If the float to be rounded up comes from a division operation a/b, you can also use integer division a//b to round down to the next integer, and increment this by one.
๐ŸŒ
Marginalia
mbeckler.org โ€บ blog
Integer division with round up | Marginalia
April 25, 2013 - >>> divide_round_up(0,4) 0 >>> divide_round_up(3,4) 1 >>> divide_round_up(4,4) 1 >>> divide_round_up(5,4) 2 >>> divide_round_up(7,4) 2 >>> divide_round_up(8,4) 2 ยท Update: My friend Joe wrote in to say โ€œThat has overflow issues if n+d>int_max. How about (n/d)+(bool(n%d))โ€. For my needs, Iโ€™m not going to be anywhere close to int_max, but itโ€™s a valid point. ... What version of Python is this? In Python 3, I think you need to use the // (floor division) operator.
๐ŸŒ
Hyperskill
hyperskill.org โ€บ university โ€บ python โ€บ integer-division-operator-in-python
Integer Division Operator in Python
December 25, 2025 - The Floor Division Operator is used in Python to perform floor division, which rounds the result down to the nearest whole number.
๐ŸŒ
LabEx
labex.io โ€บ tutorials โ€บ python-how-to-round-division-in-python-495797
How to round division in Python | LabEx
Python division techniques are crucial in various practical applications, from financial calculations to scientific computing. def calculate_tax(amount, tax_rate): return round(amount * (tax_rate / 100), 2) total_amount = 1000 tax_percentage = 8.5 tax_amount = calculate_tax(total_amount, tax_percentage) print(f"Tax Amount: ${tax_amount}")