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
🌐
Server Academy
serveracademy.com › blog › python-round-function-tutorial
Python Round() Function Tutorial - Server Academy
While round() rounds to the nearest integer or decimal, you may sometimes want to control whether the rounding always goes up or always goes down. For these scenarios, you can use Python’s math library.
🌐
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 start with the round() function. By default, it rounds a number to the nearest whole number. We'll also see how to use the function's parameters to change the type of result returned to us.
🌐
Real Python
realpython.com › python-rounding
How to Round Numbers in Python – Real Python
December 7, 2024 - Then look at the digit d in the first decimal place of m. If d is less than 5, round m down to the nearest integer. Otherwise, round m up. Finally, shift the decimal point back p places by dividing m by 10ᵖ.
🌐
DataCamp
datacamp.com › tutorial › python-round-up
How to Round Up a Number in Python | DataCamp
July 22, 2024 - The rounding half to even method, or banker’s rounding, involves rounding a number exactly halfway between two integers to the nearest even integer. Rounding a number involves adjusting a number based on the value of the fraction part. Truncating a number removes the fractional part of the number without rounding. If you want to round down instead of rounding up in Python, you can use the math.floor() function.
🌐
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. The default number of decimals is 0, meaning that the function will return the nearest integer. ... If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail: sales@w3schools.com
🌐
Note.nkmk.me
note.nkmk.me › home › python
Round Up/Down Decimals in Python: math.floor, math.ceil | note.nkmk.me
January 15, 2024 - In Python, math.floor() and math.ceil() are used to round down and up floating point numbers (float). ... Note that math.floor() rounds toward negative infinity and math.ceil() rounds toward positive infinity.
🌐
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 ...
Find elsewhere
🌐
TradingCode
tradingcode.net › python › math › round-decimals
How to round decimal places up and down in Python? • TradingCode
Inside that loop we append a rounded value to each of the three lists with Python’s append() method. The program’s last bit of code then outputs the original list and its rounded derivatives. Here’s what that displays: Original values: [22.459, 5.963, 2.335, -1.569, -0.019, -22.3] Rounded up and down to 2 decimals: [22.46, 5.96, 2.33, -1.57, -0.02, -22.3] Rounded up to 2 decimals: [22.46, 5.97, 2.34, -1.56, -0.01, -22.3] Rounded down to 2 decimals: [22.45, 5.96, 2.33, -1.57, -0.02, -22.3]
🌐
GeeksforGeeks
geeksforgeeks.org › how-to-round-numbers-in-python
How to Round Numbers in Python? - GeeksforGeeks
April 30, 2025 - Rounding up always rounds a number to the right on the number line and rounding down always rounds a number to the left on the number line.
🌐
Python Pool
pythonpool.com › home › blog › best ways to round down numbers in python
Best Ways to Round Down Numbers in Python - Python Pool
January 1, 2024 - As we can see 2.5 is rounded down to 2, whereas 3.5 is rounded up to 4. Well, this is no glitch in Python programming. It’s just how the round() function works.
🌐
Medium
medium.com › 4geeksacademy › how-to-round-in-python-cf547f8c9376
How to Round in Python? | by 4Geeks Academy | 4GeeksAcademy | Medium
June 20, 2023 - During this article, we will see several methods in python to round numbers such as round up, round down, round to a specific decimal number and round to the nearest integer number.
🌐
Reddit
reddit.com › r/learnpython › python round() function
r/learnpython on Reddit: Python Round() Function
July 9, 2021 -

Greetings,

Code: x = round(7.85, 2) print(x)

Result: 7.8

Why is that? Rounding down starts at 0 and ends at 4, and rounding up begins at 5 and ends at 9. The result should be 7.9.

Does Python have its own math rules? If so, why? Math is math...

Please and thank you ☺

🌐
Reddit
reddit.com › r/learnpython › why does round(0.5) = 0?
r/learnpython on Reddit: Why does round(0.5) = 0?
September 3, 2016 -

round (0.5) = 0

round (1.5) = 2

round (2.5) = 2

round (3.5) = 4

Is it just me or does this feel like some sort of inconsistency? Why does 0.5 round to 0, when it should round to 1?

edit: it's because python uses https://en.wikipedia.org/w/index.php?title=IEEE_754#Rounding_rules

edit2: Surprised this got this much attention. Here's a code work-around someone made:

def col_round(x):
  frac = x - math.floor(x)
  if frac < 0.5: return math.floor(x)
  return math.ceil(x)
🌐
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 ...
🌐
FavTutor
favtutor.com › blogs › round-down-python
Round Down Numbers in Python (With Examples and Code)
September 3, 2022 - Look at the diagram below. You can also think of it as Round up going to the right of the number line while Round down moves towards the left. Now that we know what Round Down is, let's look at how to round down values in programming. There are various methods to round down a number in python.
🌐
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 - Understanding these differences ... or migrate code from one environment to another. Python uses a round-half-to-even rule, often called banker’s rounding. This means that when a number lies exactly halfway between two values, it rounds to the nearest even number. Other languages, however, often round halves away from zero, which can lead to different results. ... Both numbers are halfway between two integers, but Python rounds one down (2.5 → 2) and the other up (3.5 → ...
🌐
Quora
quora.com › Why-does-the-int-function-in-Python-round-down-e-g-print-int-10-9999-gives-10-shouldnt-it-round-up-to-11
Why does the int() function in Python round down, e.g., print (int (10.9999)) gives 10, shouldn't it round up to 11? - Quora
The int() function in Python converts ... integer. For positive numbers that means it “rounds down” (floors) because removing the fraction makes the result smaller; for negative numbers it “rounds up” toward zero...
🌐
Mimo
mimo.org › glossary › python › round-function
Python round(): Rounding Numbers in Python
Using a negative value for the ndigits parameter, the round() function can round a floating-point number or integer to a multiple of 10. In the following example, we round 12345 to the nearest hundred (12300), simplifying the value. ... Python’s round() function works well in many cases.
🌐
Altcademy
altcademy.com › blog › how-to-round-down-in-python
How to round down in Python
June 13, 2023 - If the fractional part is equal to or greater than 0.5, we round up; otherwise, we round down. Rounding down, on the other hand, always rounds the number down to the nearest whole number, regardless of its fractional part.