---
description: Round() Round() 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
title: Python round() Function with EXAMPLES
image: https://www.guru99.com/images/python-round-function.png
---

 

[Skip to content](#main) 

**⚡ Smart Summary**

Python round() is a built-in function that returns a floating-point or integer value rounded to a specified number of decimal places, using banker’s rounding to break ties toward the nearest even digit.

* 🔘 **Syntax:** round(number, ndigits) accepts the value to round and an optional digit count that defaults to zero.
* ☑️ **Return type:** Omitting ndigits returns an integer, while supplying it returns a float.
* ✅ **Banker’s rounding:** Half-way values round to the nearest even number, so round(2.5) returns 2.
* 🧪 **Negative numbers:** Rounding applies to negatives too, moving -2.8 to -3 and -1.5 to -2.
* 🛠️ **Precision tools:** The decimal module and NumPy round() handle fixed-precision and array rounding.
* 🤖 **AI workflows:** Machine learning code rounds metrics, probabilities, and weights for cleaner logging and reports.

[ Read More ](javascript:void%280%29;) 

![Python round\(\) Function](https://www.guru99.com/images/python-round-function.png)

## What is the round() Function in Python?

Python round() is a built-in function available with [Python](https://www.guru99.com/python-tutorials.html). 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.

## Syntax

round(float_num, num_of_decimals)

### Parameters

* **float\_num:** The float number to be rounded.
* **num\_of\_decimals:** (optional) The number of decimals to be considered while rounding. It is optional, and if not specified, it defaults to 0, and the rounding is done to the nearest integer.

### Description

The round() method takes two arguments:

* the number to be rounded, and
* the decimal places it should consider while rounding.

The second argument is optional and defaults to 0 when not specified, and in such a case, it will round to the nearest integer, and the return type will also be an integer.

When the decimal places, i.e. the second argument, is present, it will round to the number of places given. The return type will be a float.

If the number after the decimal place given is:

* \>= 5, then + 1 will be added to the final value.
* < 5, then the final value will be returned as it is, up to the decimal places mentioned.

### Return value

It will return an integer value if the num\_of\_decimals is not given and a float value if the num\_of\_decimals is given. Please note the value will be rounded to +1 if the value after the decimal point is >= 5, else it will return the value as it is, up to the decimal places mentioned.

## How much Impact can Rounding Have? (Rounding vs Truncation)

The best example to show the impact of rounding is the stock exchange market. In the past, i.e. in the year 1982, the [Vancouver Stock Exchange](https://en.wikipedia.org/wiki/Vancouver%5FStock%5FExchange) (VSE) used to truncate the stock values to three decimal places on each trade.

It was done almost 3000 times every day. The accumulated truncations led to a loss of around 25 points per month.

An example of truncating the values versus rounding is shown below.

Consider the floating-point numbers generated below as stock values. Right now, I am generating them for a range of 1,000,000 seconds between 0.01 and 0.05.

**Examples:**

arr = [random.uniform(0.01, 0.05) for _ in range(1000000)]

To show the impact of rounding, I have written a small piece of code wherein, at first, you use the numbers up to only 3 decimal places, i.e. truncating the number after 3 decimal places.

I have the original total value, the total coming from the truncated values, and the difference between the original and truncated value.

On the same set of numbers, I have used the round() method up to 3 decimal places and calculated the sum and the difference between the original value and the rounded value.

Here are the example and the output.

**Example 1**

import random

def truncate(num):
    return int(num * 1000) / 1000

arr = [random.uniform(0.01, 0.05) for _ in range(1000000)]
sum_num = 0
sum_truncate = 0
for i in arr:
    sum_num = sum_num + i  
    sum_truncate = truncate(sum_truncate + i)
  
print("Testing by using truncating upto 3 decimal places")
print("The original sum is = ", sum_num)
print("The total using truncate = ", sum_truncate)
print("The difference from original - truncate = ", sum_num - sum_truncate)

print("\n\n")
print("Testing by using round() upto 3 decimal places")
sum_num1 = 0
sum_truncate1 = 0
for i in arr:
    sum_num1 = sum_num1 + i  
    sum_truncate1 = round(sum_truncate1 + i, 3)

print("The original sum is =", sum_num1)
print("The total using round = ", sum_truncate1)
print("The difference from original - round =", sum_num1 - sum_truncate1)

**Output:**

Testing by using truncating upto 3 decimal places
The original sum is =  29985.958619386867
The total using truncate =  29486.057
The difference from original - truncate =  499.9016193868665

Testing by using round() up to 3 decimal places
The original sum is = 29985.958619386867
The total using round =  29985.912
The difference from original - round = 0.04661938686695066

The difference between the original and truncated value is 499.9016193868665, and from round(), it is 0.04661938686695066.

The difference seems to be very big, and the example shows how the round() method helps in calculating close to accuracy.

### RELATED ARTICLES

* [Python Print() Statement: How to Print with Examples ](https://www.guru99.com/print-python-examples.html "Python Print() Statement: How to Print with Examples")
* [SciPy Tutorial: What is SciPy? (with Examples) ](https://www.guru99.com/scipy-tutorial.html "SciPy Tutorial: What is SciPy? (with Examples)")
* [Python time.sleep(): Add Delay to Your Code (Example) ](https://www.guru99.com/python-time-sleep-delay.html "Python time.sleep(): Add Delay to Your Code (Example)")
* [Python Matrix: Transpose, Multiply, NumPy Arrays ](https://www.guru99.com/python-matrix.html "Python Matrix: Transpose, Multiply, NumPy Arrays")

## Example: Rounding Float Numbers

In this program, we will see how rounding works on floating numbers.

# testing round()

float_num1 = 10.60 # here the value will be rounded to 11 as after the decimal point the number is 6 that is >5

float_num2 = 10.40 # here the value will be rounded to 10 as after the decimal point the number is 4 that is <=5

float_num3 = 10.3456 # here the value will be 10.35 as after the 2 decimal points the value >=5

float_num4 = 10.3445 #here the value will be 10.34 as after the 2 decimal points the value is <5

print("The rounded value without num_of_decimals is :", round(float_num1))
print("The rounded value without num_of_decimals is :", round(float_num2))
print("The rounded value with num_of_decimals as 2 is :", round(float_num3, 2))
print("The rounded value with num_of_decimals as 2 is :", round(float_num4, 2))

**Output:**

The rounded value without num_of_decimals is : 11
The rounded value without num_of_decimals is : 10
The rounded value with num_of_decimals as 2 is : 10.35
The rounded value with num_of_decimals as 2 is : 10.34

## Example: Rounding Integer Values

If you happen to use round() on an integer value, it will just return you the number back without any changes.

# testing round() on a integer

num = 15

print("The output is", round(num))

**Output:**

The output is 15

## Example: Rounding on Negative Numbers

Let us see a few examples of how rounding works on negative numbers.

# testing round()

num = -2.8
num1 = -1.5
print("The value after rounding is", round(num))
print("The value after rounding is", round(num1))

**Output:**

C:\pythontest>python testround.py
The value after rounding is -3
The value after rounding is -2

## Example: Round NumPy Arrays

How do you round NumPy [arrays in Python](https://www.guru99.com/python-arrays.html)?

To solve this, we can make use of the NumPy module and use the numpy.round() or numpy.around() method, as shown in the example below.

**Using numpy.round()**

# testing round()
import numpy as np

arr = [-0.341111, 1.455098989, 4.232323, -0.3432326, 7.626632, 5.122323]

arr1 = np.round(arr, 2)

print(arr1)

**Output:**

C:\pythontest>python testround.py
[-0.34  1.46  4.23 -0.34  7.63  5.12]

We can also use numpy.around(), which gives you the same result as numpy.round() shown above.

## Example: Decimal Module

In addition to the round() function, Python has a decimal module that helps in handling decimal numbers more accurately.

The Decimal module comes with rounding types, as shown below:

* **ROUND\_CEILING:** it will round towards Infinity.
* **ROUND\_DOWN:** it will round the value towards zero.
* **ROUND\_FLOOR:** it will round towards -Infinity.
* **ROUND\_HALF\_DOWN:** it will round to the nearest value going towards zero.
* **ROUND\_HALF\_EVEN:** it will round to the nearest value going to the nearest even integer.
* **ROUND\_HALF\_UP:** it will round to the nearest value going away from zero.
* **ROUND\_UP:** it will round where the value will go away from zero.

In decimal, the quantize() method helps to round to a fixed number of decimal places, and you can specify the rounding to be used, as shown in the example below.

**Example:** Using round() and decimal methods

import  decimal
round_num = 15.456

final_val = round(round_num, 2)

#Using decimal module
final_val1 = decimal.Decimal(round_num).quantize(decimal.Decimal('0.00'), rounding=decimal.ROUND_CEILING)
final_val2 = decimal.Decimal(round_num).quantize(decimal.Decimal('0.00'), rounding=decimal.ROUND_DOWN)
final_val3 = decimal.Decimal(round_num).quantize(decimal.Decimal('0.00'), rounding=decimal.ROUND_FLOOR)
final_val4 = decimal.Decimal(round_num).quantize(decimal.Decimal('0.00'), rounding=decimal.ROUND_HALF_DOWN)
final_val5 = decimal.Decimal(round_num).quantize(decimal.Decimal('0.00'), rounding=decimal.ROUND_HALF_EVEN)
final_val6 = decimal.Decimal(round_num).quantize(decimal.Decimal('0.00'), rounding=decimal.ROUND_HALF_UP)
final_val7 = decimal.Decimal(round_num).quantize(decimal.Decimal('0.00'), rounding=decimal.ROUND_UP)

print("Using round()", final_val)
print("Using Decimal - ROUND_CEILING ",final_val1)
print("Using Decimal - ROUND_DOWN ",final_val2)
print("Using Decimal - ROUND_FLOOR ",final_val3)
print("Using Decimal - ROUND_HALF_DOWN ",final_val4)
print("Using Decimal - ROUND_HALF_EVEN ",final_val5)
print("Using Decimal - ROUND_HALF_UP ",final_val6)
print("Using Decimal - ROUND_UP ",final_val7)

**Output:**

Using round() 15.46
Using Decimal - ROUND_CEILING  15.46
Using Decimal - ROUND_DOWN  15.45
Using Decimal - ROUND_FLOOR  15.45
Using Decimal - ROUND_HALF_DOWN  15.46
Using Decimal - ROUND_HALF_EVEN  15.46
Using Decimal - ROUND_HALF_UP  15.46
Using Decimal - ROUND_UP  15.46

## FAQs

🎯 Does Python round() always round 0.5 up?

No. Python 3 uses round half to even (banker’s rounding) for ties, so round(0.5) is 0, round(2.5) is 2, and round(3.5) is 4\. This reduces cumulative bias.

🧮 Why does round(2.675, 2) return 2.67 instead of 2.68?

Because 2.675 cannot be stored exactly in binary floating point; it is actually held as about 2.6749999999999998, so round() rounds down. For exact results, use decimal.Decimal(‘2.675’).

⬆️ How do I always round up or down instead of to the nearest value?

Use the math module: math.ceil(x) always rounds up, math.floor(x) always rounds down, and int(x) truncates toward zero. round() itself cannot force a fixed direction.

🔟 How can I round to the nearest 10 or 100 in Python?

Pass a negative second argument: round(12345, -1) gives 12340, round(12345, -2) gives 12300, and round(12345, -3) gives 12000\. Negative ndigits rounds left of the decimal point.

🖋️ Should I use round() or an f-string to show two decimal places?

round(x, 2) changes the value used in later math, while f'{x:.2f}’ only formats the display and keeps the number intact. Use round() for calculations, f-strings for output.

♻️ Does round() modify the original number?

No. Numbers are immutable, so round() returns a new value without changing its input. Assign it, for example result = round(3.14159, 2); the original variable keeps full precision.

🤖 How is the round() function used in AI and machine learning?

Machine learning code rounds accuracy, loss, and probability values for readable logs and to map predictions to class labels. Keep full precision for gradient math and round only final displayed metrics.

⚙️ Can GitHub Copilot generate Python round() code?

Yes. AI assistants such as GitHub Copilot autocomplete round(), np.round(), and decimal rounding from a comment or function name, and agentic tools refactor manual formatting into round() calls, though the chosen precision still needs review.

#### Summarize this post with:

ChatGPT Perplexity Grok Google AI 

**Stay Updated on AI** **Get Weekly AI Skills, Trends, Actionable Advice.** 

##### Sign up for the newsletter

Subscribe for Free 

You have successfully subscribed.  
Please check your inbox. 

![AI-Newsletter]() Chosen by over **350,000+** professionals 

[Scroll to top ](#wrapper)Scroll to top 

× 

Toggle Menu Close 

Search for: 

Search

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://www.guru99.com/#organization","name":"Guru99","sameAs":["https://www.facebook.com/Guru99Official","https://twitter.com/guru99com"],"logo":{"@type":"ImageObject","@id":"https://www.guru99.com/#logo","url":"https://www.guru99.com/images/guru99-logo-v1-150x59.png","contentUrl":"https://www.guru99.com/images/guru99-logo-v1-150x59.png","caption":"Guru99","inLanguage":"en-US"}},{"@type":"WebSite","@id":"https://www.guru99.com/#website","url":"https://www.guru99.com","name":"Guru99","publisher":{"@id":"https://www.guru99.com/#organization"},"inLanguage":"en-US"},{"@type":"ImageObject","@id":"https://www.guru99.com/images/python-round-function.png","url":"https://www.guru99.com/images/python-round-function.png","width":"700","height":"250","caption":"Python round() function","inLanguage":"en-US"},{"@type":"BreadcrumbList","@id":"https://www.guru99.com/round-function-python.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":"1","item":{"@id":"https://www.guru99.com","name":"Home"}},{"@type":"ListItem","position":"2","item":{"@id":"https://www.guru99.com/python","name":"Python"}},{"@type":"ListItem","position":"3","item":{"@id":"https://www.guru99.com/round-function-python.html","name":"Python round() Function with EXAMPLES"}}]},{"@type":"WebPage","@id":"https://www.guru99.com/round-function-python.html#webpage","url":"https://www.guru99.com/round-function-python.html","name":"Python round() Function with EXAMPLES","dateModified":"2026-07-10T13:18:11+05:30","isPartOf":{"@id":"https://www.guru99.com/#website"},"primaryImageOfPage":{"@id":"https://www.guru99.com/images/python-round-function.png"},"inLanguage":"en-US","breadcrumb":{"@id":"https://www.guru99.com/round-function-python.html#breadcrumb"}},{"@type":"Person","@id":"https://www.guru99.com/author/logan","name":"Logan Young","description":"I'm Logan Young, an expert in Python, providing top-tier tutorials and guides to enhance your coding skills and streamline your learning journey.","url":"https://www.guru99.com/author/logan","image":{"@type":"ImageObject","@id":"https://www.guru99.com/images/logan-young-author.png","url":"https://www.guru99.com/images/logan-young-author.png","caption":"Logan Young","inLanguage":"en-US"},"worksFor":{"@id":"https://www.guru99.com/#organization"}},{"articleSection":"Python","headline":"Python round() Function with EXAMPLES","description":"Round() Round() 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","keywords":"python","speakable":{"@type":"SpeakableSpecification","cssSelector":[".entry-title",".summary"]},"@type":"Article","author":{"@id":"https://www.guru99.com/author/logan","name":"Logan Young"},"dateModified":"2026-07-10T13:18:11+05:30","image":{"@id":"https://www.guru99.com/images/python-round-function.png"},"copyrightYear":"2026","name":"Python round() Function with EXAMPLES","subjectOf":[{"@type":"FAQPage","mainEntity":[{"@type":"Question","name":"Does Python round() always round 0.5 up?","acceptedAnswer":{"@type":"Answer","text":"No. Python 3 uses round half to even (banker's rounding) for ties, so round(0.5) is 0, round(2.5) is 2, and round(3.5) is 4. This reduces cumulative bias."}},{"@type":"Question","name":"Why does round(2.675, 2) return 2.67 instead of 2.68?","acceptedAnswer":{"@type":"Answer","text":"Because 2.675 cannot be stored exactly in binary floating point; it is actually held as about 2.6749999999999998, so round() rounds down. For exact results, use decimal.Decimal('2.675')."}},{"@type":"Question","name":"How do I always round up or down instead of to the nearest value?","acceptedAnswer":{"@type":"Answer","text":"Use the math module: math.ceil(x) always rounds up, math.floor(x) always rounds down, and int(x) truncates toward zero. round() itself cannot force a fixed direction."}},{"@type":"Question","name":"How can I round to the nearest 10 or 100 in Python?","acceptedAnswer":{"@type":"Answer","text":"Pass a negative second argument: round(12345, -1) gives 12340, round(12345, -2) gives 12300, and round(12345, -3) gives 12000. Negative ndigits rounds left of the decimal point."}},{"@type":"Question","name":"Should I use round() or an f-string to show two decimal places?","acceptedAnswer":{"@type":"Answer","text":"round(x, 2) changes the value used in later math, while f'{x:.2f}' only formats the display and keeps the number intact. Use round() for calculations, f-strings for output."}},{"@type":"Question","name":"Does round() modify the original number?","acceptedAnswer":{"@type":"Answer","text":"No. Numbers are immutable, so round() returns a new value without changing its input. Assign it, for example result = round(3.14159, 2); the original variable keeps full precision."}},{"@type":"Question","name":"How is the round() function used in AI and machine learning?","acceptedAnswer":{"@type":"Answer","text":"Machine learning code rounds accuracy, loss, and probability values for readable logs and to map predictions to class labels. Keep full precision for gradient math and round only final displayed metrics."}},{"@type":"Question","name":"Can GitHub Copilot generate Python round() code?","acceptedAnswer":{"@type":"Answer","text":"Yes. AI assistants such as GitHub Copilot autocomplete round(), np.round(), and decimal rounding from a comment or function name, and agentic tools refactor manual formatting into round() calls, though the chosen precision still needs review."}}]}],"@id":"https://www.guru99.com/round-function-python.html#schema-1139351","isPartOf":{"@id":"https://www.guru99.com/round-function-python.html#webpage"},"publisher":{"@id":"https://www.guru99.com/#organization"},"inLanguage":"en-US","mainEntityOfPage":{"@id":"https://www.guru99.com/round-function-python.html#webpage"}}]}
```
