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
🌐
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.
Discussions

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
🌐 r/learnpython
7
1
January 23, 2019
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
🌐 discuss.python.org
0
January 25, 2023
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
🌐 r/learnpython
1
2
January 31, 2022
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
🌐 r/learnpython
12
2
May 18, 2021
🌐
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.
🌐
DataCamp
datacamp.com › tutorial › python-round-up
How to Round Up a Number in Python | DataCamp
July 22, 2024 - Python uses the math module, NumPy, and Pandas libraries to offer different methods of rounding up numbers. The math.ceil() function from math is used to round up a number to the nearest integer.
🌐
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
🌐
Server Academy
serveracademy.com › blog › python-round-function-tutorial
Python Round() Function Tutorial - Server Academy
In this tutorial, we’ll cover ... for common rounding tasks. The round() function in Python rounds a floating-point number to the nearest integer or specified number of decimal places....
🌐
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.
Find elsewhere
🌐
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.
🌐
Real Python
realpython.com › python-rounding
How to Round Numbers in Python – Real Python
December 7, 2024 - To implement the rounding down strategy in Python, you can follow the same algorithm that you used for both trunctate() and round_up(). First shift the decimal point, then round to an integer, and finally shift the decimal point back.
🌐
LabEx
labex.io › tutorials › python-how-to-round-up-a-number-to-the-nearest-integer-in-python-398061
How to round up a number to the nearest integer in Python | LabEx
In Python, the process of rounding ... or to a specified number of decimal places. math.ceil(): This function from the math module rounds a number up to the nearest integer....
🌐
Microsoft Learn
learn.microsoft.com › en-us › power-platform › power-fx › reference › function-round
Int, Round, RoundDown, RoundUp, and Trunc functions - Power Platform | Microsoft Learn
RoundUp always rounds up to the next higher number, away from zero. The number of decimal places can be specified for these functions: The Int and Trunc functions round a number to an integer (whole number without a decimal):
🌐
Analytics Vidhya
analyticsvidhya.com › home › python round up function
Python Round Up Function
February 4, 2025 - Here, NumPy’s ceil() function rounds each element in the array up to the nearest integer. For applications requiring high precision (e.g., financial calculations), Python’s decimal module allows for accurate rounding operations.
🌐
GeeksforGeeks
geeksforgeeks.org › python › how-to-round-numbers-in-python
How to Round Numbers in Python? - GeeksforGeeks
July 15, 2025 - Python’s built-in round() function rounds a number to a given precision. If no precision is specified, it rounds to the nearest integer.
🌐
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.
🌐
Note.nkmk.me
note.nkmk.me › home › python
Round Up/Down Decimals in Python: math.floor, math.ceil
January 15, 2024 - Convert a string to a number (int, float) in Python · print(int('10')) # 10 # print(int('10.123')) # ValueError: invalid literal for int() with base 10: '10.123' print(int('FF', 16)) # 255 ... Considering negative values, there are four ways to round up and down.
🌐
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.