The round() function in Python is a built-in function used to round a number to the nearest integer or to a specified number of decimal places.

  • Basic Usage: round(number) rounds to the nearest integer. For example, round(3.7) returns 4, and round(3.2) returns 3.

  • Decimal Places: round(number, ndigits) rounds to ndigits decimal places. For example, round(3.14159, 2) returns 3.14.

  • Bankers' Rounding: When a number is exactly halfway between two integers (e.g., 2.5 or 3.5), Python uses "round half to even" โ€” rounding to the nearest even number. For example, round(2.5) returns 2, and round(3.5) returns 4.

  • Negative ndigits: You can round to the nearest 10, 100, etc., by using a negative ndigits. For example, round(1234, -2) returns 1200 (nearest hundred).

  • Return Type: If ndigits is omitted or 0, round() returns an integer. Otherwise, it returns a float.

  • Floating-Point Precision: Due to how floating-point numbers are stored, some results may be unexpected (e.g., round(2.675, 2) returns 2.67, not 2.68). For high-precision tasks like financial calculations, use the decimal module instead.

For rounding up or down specifically, use math.ceil() (always round up) or math.floor() (always round down). To round numbers in a list or array, use list comprehensions or numpy.round().

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 ... Training ... The round() function returns a floating point number that is a rounded version of the specified number, with the specified number of decimals....
๐ŸŒ
Python documentation
docs.python.org โ€บ 3 โ€บ library โ€บ functions.html
Built-in Functions โ€” Python 3.14.3 documentation
2 weeks ago - For the built-in types supporting round(), values are rounded to the closest multiple of 10 to the power minus ndigits; if two multiples are equally close, rounding is done toward the even choice (so, for example, both round(0.5) and round(-0.5) are 0, and round(1.5) is 2). Any integer value is valid for ndigits (positive, zero, or negative). The return value is an integer if ndigits is omitted or None. Otherwise, the return value has the same type as number. For a general Python object number, round delegates to number.__round__.
Discussions

How does round function handle scientific notation?
Iโ€™m currently working on a calculator program and am currently dealing with rounding. I want to round to 5 decimal places. Problem is, some functions in my program (for instance, tan(pi/2)) return scientific notation. Iโ€™m going to use tan(pi/2) as my example. More on discuss.python.org
๐ŸŒ discuss.python.org
0
December 5, 2022
python - How do you round UP a number? - Stack Overflow
How does one round a number UP in Python? I tried round(number) but it rounds the number down. Here is an example: round(2.3) = 2.0 and not 3, as I would like. Then I tried int(number + .5) but it More on stackoverflow.com
๐ŸŒ stackoverflow.com
python - How to properly round-up half float numbers? - Stack Overflow
It will round number up or down properly. ... Time and time I am shocked there is not internal function like this. I mean, it is not like people nowadays use a lot of numpy and math in python to implement numerical algorithms.... More on stackoverflow.com
๐ŸŒ stackoverflow.com
Given that round(0.5)==0 in Python, how do I round correctly?

http://docs.python.org/library/decimal.html

from decimal import *
number = Decimal('0.5')
print round(number)

is one way to do it.

More on reddit.com
๐ŸŒ r/learnpython
8
6
June 15, 2008
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ round-function-python
round() function in Python - GeeksforGeeks
Python round() function is a built-in function available with Python. 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 ...
Published ย  August 7, 2024
๐ŸŒ
Leapcell
leapcell.io โ€บ blog โ€บ how-to-round-numbers-in-python
How to Round Numbers in Python | Leapcell
July 25, 2025 - NumPy's round() function rounds each element in the array to the specified number of decimal places. Python provides multiple methods for rounding numbers:
๐ŸŒ
Mimo
mimo.org โ€บ glossary โ€บ python โ€บ round-function
Python round(): Rounding Numbers in Python
The Python round() function rounds floating-point numbers to a specified number of decimal places.
๐ŸŒ
Python.org
discuss.python.org โ€บ python help
How does round function handle scientific notation? - Python Help - Discussions on Python.org
December 5, 2022 - Iโ€™m currently working on a calculator program and am currently dealing with rounding. I want to round to 5 decimal places. Problem is, some functions in my program (for instance, tan(pi/2)) return scientific notation. Iโ€™m going to use tan(pi/2) as my example.
Find elsewhere
๐ŸŒ
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 - The main purpose of round() is to make numbers simpler and easier to work with. You can round a number to the nearest whole number, or you can round it to a certain number of decimal places. ... ndigits (optional): This tells Python how many decimal places you want.
๐ŸŒ
Tutorial Teacher
tutorialsteacher.com โ€บ python โ€บ python-round
Python round
The round() function returns a number, rounded to precision of specified position after decimal point.
๐ŸŒ
Server Academy
serveracademy.com โ€บ blog โ€บ python-round-function-tutorial
Python Round() Function Tutorial - Server Academy
The round() function in Python rounds a floating-point number to the nearest integer or specified number of decimal places.
๐ŸŒ
Real Python
realpython.com โ€บ python-rounding
How to Round Numbers in Python โ€“ Real Python
December 7, 2024 - Python has a built-in round() function that takes two numeric arguments, n and ndigits, and returns the number n rounded to ndigits. The ndigits argument defaults to zero, so leaving it out results in a number rounded to an integer.
๐ŸŒ
ZetCode
zetcode.com โ€บ python โ€บ round-builtin
Python round Function - Complete Guide
April 11, 2025 - This comprehensive guide explores Python's round function, which returns a floating point number rounded to specified digits.
๐ŸŒ
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 simplest way to round a number in Python is to use the built-in round() function. The round() function takes a number as the first argument and an optional second argument to specify the number of decimal places to round to.
๐ŸŒ
Programiz
programiz.com โ€บ python-programming โ€บ methods โ€บ built-in โ€บ round
Python round()
The round() function returns a floating-point number rounded to the specified number of decimals. In this tutorial, we will learn about Python round() in detail with the help of examples.
๐ŸŒ
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 ...
๐ŸŒ
Python documentation
docs.python.org โ€บ 3 โ€บ library โ€บ random.html
random โ€” Generate pseudo-random numbers
3 weeks ago - from heapq import heapify, heapreplace from random import expovariate, gauss from statistics import mean, quantiles average_arrival_interval = 5.6 average_service_time = 15.0 stdev_service_time = 3.5 num_servers = 3 waits = [] arrival_time = 0.0 servers = [0.0] * num_servers # time when each server becomes available heapify(servers) for i in range(1_000_000): arrival_time += expovariate(1.0 / average_arrival_interval) next_server_available = servers[0] wait = max(0.0, next_server_available - arrival_time) waits.append(wait) service_duration = max(0.0, gauss(average_service_time, stdev_service_time)) service_completed = arrival_time + wait + service_duration heapreplace(servers, service_completed) print(f'Mean wait: {mean(waits):.1f} Max wait: {max(waits):.1f}') print('Quartiles:', [round(q, 1) for q in quantiles(waits)])
๐ŸŒ
Unstop
unstop.com โ€บ home โ€บ blog โ€บ python round() function | syntax, errors, uses & more (+codes)
Python round() Function | Syntax, Errors, Uses & More (+Codes)
February 3, 2025 - The round() function in Python rounds a number to the nearest integer or specified decimal places. It returns a float or an integer value.
๐ŸŒ
LabEx
labex.io โ€บ tutorials โ€บ python-how-to-round-up-numbers-in-python-418689
How to round up numbers in Python | LabEx
Number rounding is a fundamental mathematical operation that allows you to simplify numeric values by reducing their precision. In Python, rounding helps you convert floating-point numbers to integers or limit decimal places based on specific rules.
๐ŸŒ
Hyperskill
hyperskill.org โ€บ university โ€บ python โ€บ rounding-and-round-in-python
Rounding and round() in Python
August 2, 2024 - Python provides a range of rounding options, including rounding to the even number (referred to as "bankers rounding") rounding up to positive infinity rounding down to negative infinity and rounding towards zero.