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
Python Examples Python Compiler ... 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....
Discussions

How to round a float to the nearest odd integer?
Take both the floor and the ceiling of your float and pick whichever one is odd. If they’re both even, your float is an even integer, so you could either subtract or add one because the distance is equal. More on reddit.com
🌐 r/Unity3D
14
1
December 11, 2023
Is there any way to automatically round floats?
You need to round floats only when printing/displaying them. Otherwise you are introducing inaccuracies to all your calculations. More on reddit.com
🌐 r/learnpython
10
0
June 11, 2023
how to limit or round a float to only two decimals without rounding up
You can try the solution here: https://stackoverflow.com/a/62435913 More on reddit.com
🌐 r/learnpython
12
5
January 23, 2024
Rounding and float point precision
I think the key is 'after summing up the corresponding products for that row'. 195.5 does have an exact representation and if you do: x = 195.5 Then x is exactly 195.5 and will always round to 196. But if x is a sum of other floats then it's not necessarily 195.5 even if it rounds to 195.5 and displays as such. For example from my testing: y = 75.27+1/3 x = 120.23+y-1/3 print(repr(x)) => 195.49999999999997 Which rounds down. This is due to the floating point precision not being 100%, which causes the sum to be slightly off. repr will show you the full precision btw so feel free to use that to check. For your purposes it's probably worth rounding to 2dp or something first before rounding to the nearest int. More on reddit.com
🌐 r/learnpython
16
4
June 12, 2025
🌐
Server Academy
serveracademy.com › blog › python-round-function-tutorial
Python Round() Function Tutorial - Server Academy
In this tutorial, we’ll cover everything you need to know about the round() function, including how to use it, how to round up or down, and practical examples for common rounding tasks.
🌐
DataCamp
datacamp.com › tutorial › python-round-up
How to Round Up a Number in Python | DataCamp
July 22, 2024 - # Import the Decimal class and the ROUND_UP rounding mode from the decimal module from decimal import Decimal, ROUND_UP # Create a Decimal object from a string representation of a floating-point number d = Decimal("-3.14159") # Round the Decimal object to nearest integer using the ROUND_UP rounding mode rounded_d_int = d.quantize(Decimal("1"), rounding=ROUND_UP) print(rounded_d_int) # prints -4
🌐
Real Python
realpython.com › python-rounding
How to Round Numbers in Python – Real Python
December 7, 2024 - Well, now you know how round_half_up(-1.225, 2) returns -1.23 even though there’s no logical error, but why does Python say that -1.225 * 100 is -122.50000000000001? Is there a bug in Python? Note*: For a hint about what’s happening, type the following in a Python interpreter session: ... Seeing this for the first time can be pretty shocking, but this is a classic example of the floating...
🌐
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 this article, we'll see some built-in functionalities that let us round numbers in Python. And we'll see how to use them with some examples. 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. 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.
🌐
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
Find elsewhere
🌐
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). Contents · Round down (= take the floor): math.floor() Round up (= take the ceiling): math.ceil() Difference between math.floor() and int() ...
🌐
Programiz
programiz.com › python-programming › methods › built-in › round
Python round()
from decimal import Decimal # normal float num = 2.675 · print(round(num, 2)) # using decimal.Decimal (passed float as string for precision) num = Decimal('2.675')
🌐
GeeksforGeeks
geeksforgeeks.org › python › round-function-python
round() function in Python - GeeksforGeeks
In this article, we will see Python how to Round Numbers using round() function. ... if a decimal number is given, then it will round off to the closest multiple of 10 to the power minus ndigits.
Published   August 7, 2024
🌐
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 ...
🌐
TutorialsPoint
tutorialspoint.com › home › articles on trending technologies › how do you round up a float number in python?
How do you round up a float number in Python?
October 26, 2023 - The round() function gives a floating point number with a specified number of decimals which is the rounded version of the specified number. The function will return the nearest integer because the default value for the number of decimals is ...
🌐
DataCamp
datacamp.com › tutorial › python-round-to-two-decimal-places
How to Round to 2 Decimal Places in Python | DataCamp
August 8, 2024 - The round() function is Python’s built-in function for rounding float point numbers to the specified number of decimal places. You can specify the number of decimal places to round by providing a value in the second argument.
🌐
Easy Tweaks
easytweaks.com › round-up-down-float-python
How to round a number or float list in Python?
February 25, 2021 - Skip to content · BECOMING MORE EFFICIENT WITH TECH · HELPING TO REDUCE BUSY WORK SO YOU CAN FOCUS ON STUFF THAT MATTERS · Check out our latest posts: · How to change the default Email Account in Gmail and Outlook · How to fix Windows 11 Not detecting Bluetooth headset · How to fix Microsoft ...
🌐
Analytics Vidhya
analyticsvidhya.com › home › 6 ways to round floating value to two decimals in python
6 Ways to Round Floating Value to Two Decimals in Python
November 4, 2024 - This method is useful for generating output with variable content in Python applications. However, modern formatting methods like f-strings and the format() function are replacing it. num = 54.45356 # Using the % operator for string formatting rounded_num = "%.2f" % num print(rounded_num) ... To format a floating-point number with two decimal places in Python, you can use the .2f format specifier.
🌐
GeeksforGeeks
geeksforgeeks.org › python › how-to-round-floating-value-to-two-decimals-in-python
How to Round Floating Value to Two Decimals in Python - GeeksforGeeks
July 23, 2025 - In Python, we can use the decimal module to round floating-point numbers to a specific number of decimal places with higher precision and control compared to the built-in floating-point arithmetic.
🌐
Finxter
blog.finxter.com › home › learn python blog › how to round a number up in python?
How to Round a Number Up in Python? - Be on the Right Side of Change
April 22, 2022 - To round a number up in Python, import the math library with import math, and call math.ceil(number) that returns the ceiling of number, i.e., the smallest integer greater than or equal to number. In general, there are at least four ways to round a float number x up in Python:
🌐
Python
docs.python.org › 3 › library › decimal.html
decimal — Decimal fixed-point and floating-point arithmetic
Rounding options include ROUND_CEILING, ROUND_DOWN, ROUND_FLOOR, ROUND_HALF_DOWN, ROUND_HALF_EVEN, ROUND_HALF_UP, ROUND_UP, and ROUND_05UP. Signals are groups of exceptional conditions arising during the course of computation. Depending on the needs of the application, signals may be ignored, considered as informational, or treated as exceptions. The signals in the decimal module are: Clamped, InvalidOperation, DivisionByZero, Inexact, Rounded, Subnormal, Overflow, Underflow and FloatOperation.
🌐
Guru99
guru99.com › home › python › python round() function with examples
Python round() function with EXAMPLES
August 12, 2024 - Using round() 15.46 Using Decimal - ROUND_CEILING 15.46 Using Decimal - ROUND_DOWN 15.45 Using Decimal - ROUND_FLOOR 15.45 Using Decimal - ROUND_HALF_DOWN 15.46 Using Decimal - ROUND_HALF_EVEN 15.46 Using Decimal - ROUND_HALF_UP 15.46 Using Decimal - ROUND_UP 15.46 · Round(float_num, Num_of_decimals) is a built-in function available with python.
🌐
4Geeks
4geeks.com › how-to › how-to-round-in-python
How to Round in Python?
July 16, 2025 - 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. Here is a code snippet that shows how to round a number in Python: ... In the previous example we rounded to the nearest integer number the variable number which value was 3.78. The result is the stored in rounded_number and it is printed in the console as 4. This process implies to get a specific float number into the nearest integer number or even to a specific precision of decimals.