I don't know of a standard function in Python, but this works for me:

Python 3

def myround(x, base=5):
    return base * round(x/base)

It is easy to see why the above works. You want to make sure that your number divided by 5 is an integer, correctly rounded. So, we first do exactly that (round(x/5)), and then since we divided by 5, we multiply by 5 as well.

I made the function more generic by giving it a base parameter, defaulting to 5.

Python 2

In Python 2, float(x) would be needed to ensure that / does floating-point division, and a final conversion to int is needed because round() returns a floating-point value in Python 2.

def myround(x, base=5):
    return int(base * round(float(x)/base))
Answer from Alok Singhal on Stack Overflow
🌐
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 · ❮ Built-in Functions · Round a number to only two decimals: x = round(5.76543, 2) print(x) Try it Yourself » ·
🌐
Mimo
mimo.org › glossary › python › round-function
Python round(): Rounding Numbers in Python
Python · Open in Mimo · Open in Mimo · Copy Code · result = 2.718281828459 rounded_result = round(result, 5) print(rounded_result) # Outputs: 2.71828 · An e-commerce platform might use the round() function to calculate the totals of an order. By rounding the total, the platform can ensure customers pay the correct amount to two decimal places.
People also ask

How does the Python round function work?
Python uses round half to even logic. Numbers exactly halfway between two integers are rounded to the nearest even number. For example, round(2.5) becomes 2, while round(3.5) becomes 4. This reduces rounding bias in large datasets or repeated calculations.
🌐
knowledgehut.com
knowledgehut.com › home › blog › data science › understanding python round function: guide to precise rounding
Round Function in Python [2025] – Explained for Beginners
How does Python round function handle 0.5 values?
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.
🌐
knowledgehut.com
knowledgehut.com › home › blog › data science › understanding python round function: guide to precise rounding
Round Function in Python [2025] – Explained for Beginners
What is the syntax of the Python round function?
The syntax is round(number, ndigits). number is the value to round, and ndigits is optional, defining the decimal places. Omitting ndigits rounds to the nearest integer, while negative values round to tens, hundreds, or thousands.
🌐
knowledgehut.com
knowledgehut.com › home › blog › data science › understanding python round function: guide to precise rounding
Round Function in Python [2025] – Explained for Beginners
🌐
Real Python
realpython.com › python-rounding
How to Round Numbers in Python – Real Python
December 7, 2024 - If n is negative and d < 5, round up. After rounding according to one of the above four rules, you then shift the decimal place back to the left. Given a number n and a value for decimals, you could implement this in Python by using round_half_up() and round_half_down(): ... That looks pretty good, but there’s actually a simpler way! If you first take the absolute value of n using Python’s built-in abs() function, then you can just use round_half_up() to round the number.
🌐
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 - Python also uses a method called banker’s rounding for numbers ending with .5. This means it rounds to the nearest even number instead of always rounding up.
🌐
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))
🌐
GeeksforGeeks
geeksforgeeks.org › python › round-function-python
round() function in Python - GeeksforGeeks
The `round()` function in Python is used to round numbers. It takes two parameters: the number to be rounded and, optionally, the number of decimal places. If no decimal places are specified, it rounds to the nearest integer.
Published   August 7, 2024
Find elsewhere
🌐
Tutorialspoint
tutorialspoint.com › python › number_round.htm
Python round() Function
The Python round() function is used to round the given floating point number to the nearest integer value. The round is done with the specified number of decimal points. If the number of decimal places to round is not specified, it will round ...
🌐
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 - If ndigits is omitted, Python rounds the number to the nearest integer. For example, round(4.7) gives 5. This is the default behavior of the Python round function, simplifying calculations where only whole numbers are needed.
🌐
GeeksforGeeks
geeksforgeeks.org › python › how-to-round-numbers-in-python
How to Round Numbers in Python? - GeeksforGeeks
July 15, 2025 - Python provides various methods ... techniques for rounding numbers in Python, along with examples. For example, Input is 3.5 then Output should be 4. Python’s built-in round() function rounds a number to a given precision....
🌐
Real Python
realpython.com › ref › builtin-functions › round
round() | Python’s Built-in Functions – Real Python
>>> prices = [19.995, 20.005, 10.5, 5.678] >>> rounded_prices = [round(price, 2) for price in prices] >>> rounded_prices [20.0, 20.01, 10.5, 5.68] In this example, round() helps you format the prices to two decimal places, making them suitable for display in a financial context. ... In this tutorial, you'll learn what kinds of mistakes you might make when rounding numbers and how you can best manage or avoid them. It's a great place to start for the early-intermediate Python developer interested in using Python for finance, data science, or scientific computing.
🌐
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')
🌐
Software Testing Help
softwaretestinghelp.com › home › python › python round function: rounding numbers in python
Python Round Function: Rounding Numbers in Python
April 1, 2025 - The number after the decimal point, in this case, is 7, which falls between 5 and 9. Hence, we round up by adding 1 to 6. Finally, we discard all numbers after the decimal point and bring them back to their normal position, which gives us 3.457 · One of the built-in functions provided by Python to ...
🌐
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 - # Example 7: Rounding in pandas import pandas as pd data = {'values': [2.345, 5.678, 9.012]} df = pd.DataFrame(data) df['rounded_values'] = df['values'].round(decimals=1) print(df) # Output: # values rounded_values # 0 2.345 2.3 # 1 5.678 5.7 # 2 9.012 9.0 · When rounding a large number of values in performance-critical applications, using NumPy or pandas might be more efficient than using Python’s built-in round() function in a loop.
🌐
Python.org
discuss.python.org › python help
Round function should be improved - Python Help - Discussions on Python.org
July 5, 2024 - the round function should be improved, the round function is supposed to round up numbers that are in a decimal format. I have found that the round function only looks at the first decimal point, for example when I enter this: print(round(1.45), round(1.54)) as a result I get: 1 2 I have created some new code that works as the round function is supposed to: def rounding(num): #this code was made by anon #this looks to see if the num is a decimal if num % 1 != 0: #sees ...
🌐
Python Reference
python-reference.readthedocs.io › en › latest › docs › functions › round.html
round — Python Reference (The Right Way) 0.1 documentation
Values are rounded to the closest multiple of 10 to the power minus decimalplaces; if two multiples are equally close, rounding is done away from 0 (so. for example, round(0.5) is 1.0 and round(-0.5) is -1.0).
🌐
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 ☺

🌐
IONOS
ionos.com › digital guide › websites › web development › python round function
What is Python round()? - IONOS
May 28, 2025 - If you want to round numbers in Python, the built-in round() function is the simplest and most effective method for doing so. This function returns a floating-point number that is rounded to the nearest value based on the number of decimal places you specify...
🌐
Scaler
scaler.com › home › topics › round function in python
round() Function in Python | Scaler Topics
December 3, 2023 - In this section, we will discuss how the python round() function will break ties. A tie occurs when the last digit of a number is 5 and the last needs to be removed while rounding.