you can use the round() function:

https://www.w3schools.com/python/ref_func_round.asp

Example:

p = round(50.12345,3)
print(p)

Output:

 50.123

Example 2:

# for integers
print(round(15))

# for floating point
print(round(51.6))
print(round(51.5))
print(round(51.4))

Output:

15  
52  
52  
51  
Answer from PrometheusKain 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.
🌐
Cach3
w3schools.com.cach3.com › python › ref_func_round.asp.html
Python round() Function - W3Schools
Python Overview Python Built-in ... Python Quiz Python Certificate ... The round() function returns a floating point number that is a rounded version of the specified number, with the specified number of decimals....
🌐
Real Python
realpython.com › python-rounding
How to Round Numbers in Python – Real Python
December 7, 2024 - To round numbers to specific decimal places, you can use the round() function with a second argument specifying the number of decimals. For more advanced rounding strategies, you can explore Python’s decimal module or use NumPy and pandas ...
🌐
Programiz
programiz.com › python-programming › methods › built-in › round
Python round()
If you're in a situation where this precision is needed, consider using the decimal module, which is designed for floating-point arithmetic: 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 › round-function-python
round() function in Python - GeeksforGeeks
It will return you a float number that will be rounded to the decimal places which are given as input. If the decimal places to be rounded are not specified, it is considered as 0, and it will round to the nearest integer.
Published   August 7, 2024
🌐
w3resource
w3resource.com › python › built-in-function › round.php
Python round() function - w3resource
# for integers print(round(5)) # for floating point print(round(15.7)) # even choice print(round(7.3))
🌐
Scaler
scaler.com › home › topics › round function in python
round() Function in Python | Scaler Topics
December 3, 2023 - Rounding off a number to a negative number of decimal points is valid in python and it rounds off the right most digits of the number. Using negative numbers as n_digits parameter reduces the significance of the input number.
Find elsewhere
🌐
Tutorialspoint
tutorialspoint.com › python › number_round.htm
Python round() Function
The decimal points to which the given value will be rounded is '6'. Then the round() function is used to retrieve the result. # Creating the number num = -783.8934771743767623 decimalPoints = 6 res = round(num, decimalPoints) # printing the ...
🌐
W3Schools
w3schools.com › python › numpy › numpy_ufunc_rounding_decimals.asp
NumPy ufuncs - Rouning Decimals
The around() function increments preceding digit or decimal by 1 if >=5 else do nothing. E.g. round off to 1 decimal point, 3.16666 is 3.2
🌐
W3Schools
w3schools.com › python › pandas › ref_df_round.asp
Pandas DataFrame round() Method
A DataFrame with the rounded values values. This function does NOT make changes to the original DataFrame object. ... If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail: sales@w3schools.com · If you want to report an error, or if you want to make a suggestion, send us an e-mail: help@w3schools.com · HTML Tutorial CSS Tutorial JavaScript Tutorial How To Tutorial SQL Tutorial Python ...
🌐
Mimo
mimo.org › glossary › python › round-function
Python round(): Rounding Numbers in Python
Master Python from basics to advanced ... basics, data types, control flow, and more ... 1. Round to the Nearest Integer: When called with one argument, round() returns the nearest whole number....
🌐
Laurie Excel
laurieexcell.com › home › how to round up in python?
How to round up in Python? - Laurie Excel
February 19, 2025 - The math.floor() function is another built-in method in Python that rounds down a number to the nearest integer.
🌐
Python Reference
python-reference.readthedocs.io › en › latest › docs › functions › round.html
round — Python Reference (The Right Way) 0.1 documentation
Returns a floating point number rounded to a specified number of decimal places · round (number[, decimalplaces])
🌐
Software Testing Help
softwaretestinghelp.com › home › python › python round function: rounding numbers in python
Python Round Function: Rounding Numbers in Python
April 1, 2025 - This tutorial on Python Round Function explains how to round numbers in Python using different methods with multiple code examples.
🌐
RTEE Tech
blog.rteetech.com › home › development › python round up: complete guide to rounding numbers
Python Round Up | Complete Guide to Rounding Numbers
March 30, 2025 - This code divides 7 by 2 and rounds up the result using a simple check to see if there’s any remainder in the division. If the remainder is greater than zero, it adds 1 to the result, effectively rounding up the value. If you’re new to Python or need additional resources to understand the concept of rounding, W3Schools is a great place to start. They offer tutorials on Python functions and methods, including round(), ceil(), and other rounding techniques.
🌐
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 - Explore the Python round() function with this complete guide. Learn how to round numbers, understand banker’s rounding, and discover best practices.
🌐
Python Tutorial
pythontutorial.net › home › advanced python › python rounding
Python Rounding
November 24, 2022 - Introduction to the Python round() function # Rounding means making a number simpler but keeping its value close to its original value. For example, 89 rounded to the nearest ten is 90 because 89 is closer to 90 […]
Top answer
1 of 13
252

Python 3's way (called "round half to even" or "banker's rounding") is considered the standard rounding method these days, though some language implementations aren't on the bus yet.

The simple "always round 0.5 up" technique results in a slight bias toward the higher number. With large numbers of calculations, this can be significant. The Python 3 approach eliminates this issue.

There is more than one method of rounding in common use. IEEE 754, the international standard for floating-point math, defines five different rounding methods (the one used by Python 3 is the default). And there are others.

This behavior is not as widely known as it ought to be. AppleScript was, if I remember correctly, an early adopter of this rounding method. The round command in AppleScript offers several options, but round-toward-even is the default as it is in IEEE 754. Apparently the engineer who implemented the round command got so fed up with all the requests to "make it work like I learned in school" that he implemented just that: round 2.5 rounding as taught in school is a valid AppleScript command. :-)

2 of 13
58

You can control the rounding you get in Py3000 using the Decimal module:

>>> decimal.Decimal('3.5').quantize(decimal.Decimal('1'), 
    rounding=decimal.ROUND_HALF_UP)
>>> Decimal('4')

>>> decimal.Decimal('2.5').quantize(decimal.Decimal('1'),    
    rounding=decimal.ROUND_HALF_EVEN)
>>> Decimal('2')

>>> decimal.Decimal('3.5').quantize(decimal.Decimal('1'), 
    rounding=decimal.ROUND_HALF_DOWN)
>>> Decimal('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 - To round a number to a specific decimal place, pass the desired number of decimal places as the second argument to the round() function. # Example 2: Rounding to a Specific Decimal Place num = 3.14159 rounded_num = round(num, 2) # Round to 2 decimal places print(rounded_num) # Output: 3.14 · Python provides different rounding methods to handle cases where the fractional part is exactly halfway between two integers.