English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Python basic tutorial

Python flow control

Fonctions en Python

Types de données en Python

Python file operations

Python objects and classes

Python date and time

Advanced Python knowledge

Python reference manual

Python round() usage and examples

Python built-in functions

The round() function returns a floating-point number rounded to the specified decimal place.

The syntax of round() is:

round(number, ndigits)

round() parameters

round() function has two parameters:

  • number -The number to be rounded

  • ndigits (optional) -The number rounded to the given number; default is 0

round() return value

  • If ndigits is not provided, round() returns the nearest integer to the given number.

  • If ndigit is given, round() returns the number rounded to ndigit.

Example1: How does round() work in Python?

# Number is an integer
print(round(10))
# Number is a floating-point number
print(round(10.7))
# Number is a floating-point number
print(round(5.5))

Output result

10
11
6

Example2: Round a number to a specified decimal place

print(round(2.665, 2))
print(round(2.675, 2))

Output result

2.67
2.67

In the program, you may think2.675It should be rounded to2.68This is not a bug. It is considered a standard rounding method.

Python built-in functions