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 - # Create a function to check if a decimal is exactly 0.5 and round up if true def round_half_up(n): if n - int(n) == 0.5: return int(n) + 1 return round(n) # Example usage example_number = 2.5 rounded_number = round_half_up(example_number) print(rounded_number) Round half to even, or bankers' rounding, is a rounding method used to minimize bias. When a number is exactly halfway between two integers, it is rounded to the nearest even integer. This method helps to balance the rounding process by avoiding a consistent upward or downward bias. If you omit the second argument, the built-in round method rounds half to even the numbers by default. # Python round() method to round half to even print(round(2.5)) # 2 print(round(3.5)) # 4 print(round(-2.5)) # -2
🌐
Real Python
realpython.com › python-rounding
How to Round Numbers in Python – Real Python
December 7, 2024 - For example, the number 2.5 rounded to the nearest whole number is 3. The number 1.64 rounded to one decimal place is 1.6. Now open up an interpreter session and round 2.5 to the nearest whole number using Python’s built-in round() function:
🌐
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 - In our first example, we're using only one parameter – the number to be rounded, which is 2.56789. When we passed in the number variable to the round() function, it got rounded to the nearest whole number which is 3.
🌐
Mimo
mimo.org › glossary › python › round-function
Python round(): Rounding Numbers in Python
If precision is critical, Python’s decimal module provides a way to avoid floating-point precision issues. The decimal module allows you to work with decimal numbers while avoiding the rounding errors of float numbers. ... from decimal import Decimal, ROUND_HALF_UP # Create Decimal objects instead of using floats num = Decimal('2.675') # Use the quantize() method to round to two decimal places with rounding mode ROUND_HALF_UP rounded_num = num.quantize(Decimal('0.01'), rounding=ROUND_HALF_UP) print(rounded_num) # Outputs: 2.68
🌐
Server Academy
serveracademy.com › blog › python-round-function-tutorial
Python Round() Function Tutorial - Server Academy
Here’s a recap of the key points: Basic Usage: round(number, ndigits) rounds a number to the nearest integer or specified decimal place. Round Up: Use math.ceil() to always round up to the nearest integer.
🌐
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 - Bankers’ rounding is the default rounding method in Python. It rounds numbers with fractional parts that are exactly halfway between two integers to the nearest even integer. This method helps in reducing rounding biases. # Example 3: Round Half to Even (Bankers' Rounding) num1 = 2.5 num2 = 3.5 rounded_num1 = round(num1) rounded_num2 = round(num2) print(rounded_num1) # Output: 2 print(rounded_num2) # Output: 4
🌐
W3Schools
w3schools.com › python › ref_func_round.asp
Python round() Function
Python Examples Python Compiler Python Exercises Python Quiz Python Challenges Python Server Python Syllabus Python Study Plan Python Interview Q&A Python Bootcamp Python Certificate Python Training ... The round() function returns a floating point number that is a rounded version of the specified number, with the specified number of decimals.
Find elsewhere
🌐
GeeksforGeeks
geeksforgeeks.org › python › how-to-round-numbers-in-python
How to Round Numbers in Python? - GeeksforGeeks
July 15, 2025 - For example, Input is 3.5 then Output should be 4. Python’s built-in round() function rounds a number to a given precision.
🌐
Replit
replit.com › home › discover › how to round up in python
How to round up in Python
This is a common mistake when working with any Python module, not just math. Always ensure you've imported the necessary libraries before calling their functions to prevent this error from popping up. You'll get a TypeError if you give math.ceil() a value it can't handle, like a string. The function only works with real numbers, so passing it text will cause your script to fail. The following code snippet triggers this exact error. import math user_input = "3.7" rounded_up = math.ceil(user_input) # TypeError: must be real number, not str print(rounded_up)
🌐
Analytics Vidhya
analyticsvidhya.com › home › python round up function
Python Round Up Function
February 3, 2025 - In this example, 5.3 is rounded up to 6. If the number is already an integer, math.ceil() will return it unchanged. Python users can execute number rounding procedures by using different methods suitable for different purposes.
🌐
GeeksforGeeks
geeksforgeeks.org › round-function-python
round() function in Python - GeeksforGeeks
import math num = 3.6 rounded_num = math.floor(num) # rounds down to nearest integer print(rounded_num) # output: 3 rounded_num = math.ceil(num) # rounds up to nearest integer print(rounded_num) # output: 4 ... In this example, we are using ...
Published   August 7, 2024
🌐
Delft Stack
delftstack.com › home › howto › python › python round up
How to Round Up a Number in Python | Delft Stack
February 2, 2024 - So we need to give one of the values in float to the ceil function to get accurate results. If both values of an expression in the ceil function is an integer, it can produce wrong results.
🌐
GoLinuxCloud
golinuxcloud.com › home › python › python round up practical examples [5 methods]
Python round up practical examples [5 Methods] | GoLinuxCloud
November 16, 2021 - While num2 is rounded to 4 which is slightly larger than the original value and such type of rounding is known as round up.For example, see the example below: 5.5 Round up to 6 7.7 Round up to 8 3.1 Round up to 4 · In Python, we have rounded ...
🌐
Programiz
programiz.com › python-programming › methods › built-in › round
Python round()
print(round(num, 2)) # using decimal.Decimal (passed float as string for precision) num = Decimal('2.675')
🌐
Altcademy
altcademy.com › blog › how-to-round-up-in-python
How to round up in Python
June 13, 2023 - The easiest way to round up a number in Python is to use the ceil() function from the math module. The ceil() function takes a number as input and returns the smallest integer greater than or equal to the given number. Here's an example:
🌐
Note.nkmk.me
note.nkmk.me › home › python
Round Up/Down Decimals in Python: math.floor, math.ceil | note.nkmk.me
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. ... print(math.floor(10.123)) # 10 print(math.floor(-10.123)) # -11 print(math.ceil(10.123)) # 11 print(math.ceil(-10.123)) # -10 print(int(10.123)) # 10 print(int(-10.123)) # -10 ... For example, you can define a custom function that rounds toward infinity as follows.
🌐
Hyperskill
hyperskill.org › university › python › rounding-and-round-in-python
Rounding and round() in Python
August 2, 2024 - If rounding to the whole number the round() function rounds up if the decimal part is 0.5 or greater and rounds down if its less, than 0.5. For instance rounding 3.2 using round(3.2) gives 3 as output; while rounding 3.5 returns 4 according to this function. The round() function, in Python ...
🌐
Medium
medium.com › 4geeksacademy › how-to-round-in-python-cf547f8c9376
How to Round in Python? | by 4Geeks Academy | 4GeeksAcademy | Medium
June 20, 2023 - Here is a code snippet that shows how to round a number in Python: number = 3.78 rounded_number = round(number) print(rounded_number) # Output: 4 · In the previous example we rounded to the nearest integer number the variable number which value ...
🌐
KnowledgeHut
knowledgehut.com › home › blog › data science › understanding python round function: guide to precise rounding
Round Function in Python [2025] – Explained for Beginners
October 8, 2025 - Python rounds 0.5 to the nearest even number. For example, round(2.5) returns 2, and round(3.5) returns 4. This minimizes bias over multiple calculations, unlike traditional rounding which always rounds halves up.