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))
🌐
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 ...
Find elsewhere
🌐
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.
🌐
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....
🌐
Updategadh
updategadh.com › home › python interview question › how to round numbers in python
How to Round Numbers in Python
February 6, 2025 - Complete Python Course with Advance topics:-Click here · If we need to round off a number, let’s say 7.5, it will be rounded to the nearest whole number, which is 8. However, if we round 7.56 to one decimal place, the result will be 7.6. This function is especially useful when working with floating-point numbers that may have many decimal places.
🌐
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])
🌐
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.
🌐
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.
🌐
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.
🌐
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 - This function works with both integers and floating-point numbers, making it one of the most common tools for handling numeric data in Python. ... If this value is not provided, Python rounds the number to the nearest integer.
🌐
Server Academy
serveracademy.com › blog › python-round-function-tutorial
Python Round() Function Tutorial - Server Academy
Whether you need to round up, round down, or round to a specific decimal point, Python has you covered with its versatile round() function. 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.