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 Top answer 1 of 16
1382
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)))
2 of 16
348
I know this answer is for a question from a while back, but if you don't want to import math and you just want to round up, this works for me.
>>> int(21 / 5)
4
>>> int(21 / 5) + (21 % 5 > 0)
5
The first part becomes 4 and the second part evaluates to "True" if there is a remainder, which in addition True = 1; False = 0. So if there is no remainder, then it stays the same integer, but if there is a remainder it adds 1.
W3Schools
w3schools.com › python › ref_func_round.asp
Python round() Function
The round() function returns a floating point number that is a rounded version of the specified number, with the specified number of decimals. The default number of decimals is 0, meaning that the function will return the nearest integer.
How do you round up in Python?
First, it looks like the numbers are just rounding, not specifically rounding up. Look into formatted strings . More on reddit.com
Integer division
Sorry I don’t remember the ... so it didn’t add another minute,but then rounded up to 60 for display. I only caught it because I had arbitrarily chosen a number in a test that triggered the issue. ... IIUC, small integers are exactly represented in FP – so it seems ... More on discuss.python.org
Rounding a decimal/float to an integer in Python?
round rounds to the overall nearest integer. math.floor rounds to the nearest integer that's smaller than the input. math.ceil rounds to the nearest integer that's larger than the input: round(0.3) # -> 0 round(0.7) # -> 1 math.floor(0.3) # -> 0 math.floor(0.7) #- > 0 math.ceil(0.3) # -> 1 math.ceil(0.7) # -> 1 More on reddit.com
Round to whole numbers if a number is close enough?
if abs(round(value) - value) < 0.00001 x = round(value) abs is just absolute value since round(12.4)-12.4= -0.4 More on reddit.com
Videos
03:56
Rounding Up (Video) – Real Python
How to Round Numbers in Python ( Not What You Expect) - YouTube
14:05
Introduction to Rounding Numbers in Python - YouTube
30:27
Python - Rounding, Banker's Rounding (round, math.ceil ...
08:20
Understanding the Round Function (Video) – Real Python
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 - On the other hand, floor() will always round down the number to the nearest integer, even if the fractional part is closer to the higher integer. These functions are particularly useful when you want to ensure that a value is never underestimated or overestimated when working with whole numbers or discrete quantities. Bankers’ rounding is the default rounding method in Python.
GeeksforGeeks
geeksforgeeks.org › python › round-function-python
round() function in Python - GeeksforGeeks
By default, round() rounds a number to the nearest integer. However, you can also specify whether to round up or down using the round() function in combination with the math module.
Published August 7, 2024
Replit
replit.com › home › discover › how to round up in python
How to round up in Python
February 5, 2026 - This custom function, ceiling_with_precision, packages the decimal-shifting technique into a reusable tool. It’s flexible because its precision parameter lets you specify how many decimal places you need on the fly. The precision parameter defaults to 0, so it rounds up to the nearest integer if you don't provide a second argument.
Mimo
mimo.org › glossary › python › round-function
Mimo: The coding platform you need to learn Web Development, Python, and more.
Two Main Uses: Call round(number) to round to the nearest integer, or round(number, ndigits) to round to a specific number of decimal places. "Round Half to Even": In Python 3, numbers ending in .5 are rounded to the nearest even integer.
Reddit
reddit.com › r/learnpython › how do you round up in python?
r/learnpython on Reddit: How do you round up in Python?
January 23, 2019 -
Here's the code
Here's the output
Essentially, I'm asking is how do I make the numbers round up to look like the expected output.
Top answer 1 of 4
4
First, it looks like the numbers are just rounding, not specifically rounding up. Look into formatted strings .
2 of 4
2
Since you just need to print the numbers to a certain number of decimal places, you can use string formatting, like this: >>> x = 94.54545454 >>> formatted = "Result is {:.2f}".format(x) >>> print(formatted) Result is 94.55 The placeholder {:.2f} in the string indicates that you want to insert a floating point number truncated to 2 places past the decimal.
Python.org
discuss.python.org › python help
Integer division - Python Help - Discussions on Python.org
January 25, 2023 - So there seems to be some sort of rounding that’s going on when we do the plain division that’s not being done before the floor is taken in floor division – and that has me confused. Yes, integers with absolute value <= 2**53 are represented exactly in IEEE-754 double precision (CPython’s float type). 6.0 / 0.4 is exactly 15.0 because hardware division rounds it up to 15.
Hyperskill
hyperskill.org › university › python › rounding-and-round-in-python
Rounding and round() in Python
August 2, 2024 - If the fractional part is exactly halfway between two integers, it rounds towards the nearest even integer. The Decimal class provides more control over the rounding process through its quantize() method. Using this method, you can round numbers to a specific number of decimal places using a specified rounding method. Rounding methods are commonly applied in math and statistics to make calculations simpler and estimate values. The three primary rounding techniques include rounding up rounding down and rounding to the whole number.
InterServer
interserver.net › home › programming › python round() function explained: examples, decimals, and best practices
Python round() Function Explained: Examples, Decimals, and Best Practices - Interserver Tips
October 1, 2025 - This makes round() a simple and useful tool for rounding numbers in Python. The round() function is very easy to use. Let’s look at some basic examples to understand how it works. When you use round() on an integer, the number usually stays the same.
TradingCode
tradingcode.net › python › math › round-integers
How to round Python values to whole numbers? • TradingCode
The round() function rounds values of .5 towards an even integer (Python Docs, n.d. a). So .5 is round up for positive values and round down for negative values.