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
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
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 23, 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
Question: how to round In python?
You don't want to round it, you want to floor it, which lowers the number to the nearest whole. >>> import math >>> math.floor(91.66667) 91 >>> math.floor(99.9) 99 >>> math.floor(2.1) 2 More on reddit.com
🌐 r/learnpython
9
3
September 22, 2018
🌐
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:
🌐
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
🌐
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.
🌐
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
🌐
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.
Find elsewhere
🌐
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.
🌐
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
🌐
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
February 5, 2026 - 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)
🌐
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.
🌐
Analytics Vidhya
analyticsvidhya.com › home › python round up function
Python Round Up Function
February 4, 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.
🌐
GoLinuxCloud
golinuxcloud.com › home › python › python round up practical examples [5 methods]
Python round up practical examples [5 Methods] | GoLinuxCloud
November 16, 2021 - Another way to do this task is ... floating number num = 3.786847638 # Python round up number print("The number round up to 2 decimal digits is: " ,round(num, 2) )...
🌐
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 - Altcademy.com
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:
🌐
CodeRivers
coderivers.org › blog › python-round-up
Python Round Up: A Comprehensive Guide - CodeRivers
January 20, 2025 - Python follows the "round half to even" rule (also known as bankers' rounding). When the digit to be rounded is exactly 5, the number is rounded to the nearest even number. For example: - round(2.5) returns 2 - round(3.5) returns 4
🌐
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 ...
🌐
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.
🌐
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.