In this tutorial, I will explain how to round numbers to 2 decimal places in Python. As a data scientist working for a US-based company, I often need to present financial data in reports in which I had a requirement to round numbers to 2 decimal places to make the data more readable. Let’s get into the various methods to achieve this in Python with examples and screenshots of executed example code.
Round Numbers to 2 Decimal Places in Python
Python provides several ways to achieve this task. Let us see some important methods.
Read How to Generate Credit Card Numbers in Python for Testing?
Method 1. Use round() Function
Python provides a built-in function round() that allows you to round a floating-point number to a specified number of decimal places. The syntax is as follows:
round(number, decimal_places)For example, let’s say, John a sales manager in New York, wants to round the sales figure $1234.5678 to 2 decimal places:
sales = 1234.5678
rounded_sales = round(sales, 2)
print(rounded_sales) Output:
1234.57I have executed the above example code and added the screenshot below.

The round() function is simple to use. However, it’s important to note that it rounds the number based on the second decimal place. If the second decimal place is 5 or higher, it rounds up; otherwise, it rounds down.
Check out How to Check if a String Contains Only Alphanumeric Characters and Underscores in Python?
Method 2. Use f-strings
In Python 3.6 and above, you can use f-strings (formatted string literals) to round numbers to 2 decimal places. Here’s an example:
revenue = 98765.4321
print(f"The company's revenue is ${revenue:.2f}")Output:
The company's revenue is $98765.43I have executed the above example code and added the screenshot below.

In this example, .2f inside the f-string specifies that the number should be rounded to 2 decimal places and displayed as a fixed-point number.
Read How to Convert Letters to Numbers in Python?
Method 3. Use math.floor()
If you specifically want to round down to 2 decimal places, you can use the math.floor() function in combination with multiplication and division. Here’s how it works:
import math
expenses = 5432.1987
rounded_down_expenses = math.floor(expenses * 100) / 100
print(rounded_down_expenses) Output:
5432.19I have executed the above example code and added the screenshot below.

In this example, we multiply the number by 100 to shift the decimal places to the right, apply the math.floor() function to round down to the nearest integer, and then divide by 100 to shift the decimal places back.
Check out How to Pad Numbers with Leading Zeros in Python?
Method 4. Round with Decimal Module
Python’s decimal module provides support for decimal floating-point arithmetic. It offers more precise control over rounding behavior. Here’s an example:
from decimal import Decimal, ROUND_HALF_UP
profit = Decimal('7890.1234')
rounded_profit = profit.quantize(Decimal('0.01'), rounding=ROUND_HALF_UP)
print(rounded_profit) Output:
7890.12In this example, we create a Decimal object from a string and use the quantize() method to round it to 2 decimal places. The rounding parameter is set to ROUND_HALF_UP , which rounds numbers ending in 5 up (away from zero).
Check out How to Check if Input is a Number in Python?
Method 5. Format with printf-style
Python also supports printf-style formatting using the % operator. Here’s an example of rounding a number to 2 decimal places using this method:
total_assets = 1234567.8901
print("The company's total assets are $%.2f" % total_assets) Output:
The company's total assets are $1234567.89The %.2f format specifier indicates that the number should be displayed as a floating-point number with 2 decimal places.
Read What are Floating Point Numbers in Python?
Example
Let’s consider a real-world scenario where rounding numbers to 2 decimal places is important. Sarah, a financial analyst in Los Angeles, is preparing a budget report for her company. She has a list of expenses that need to be rounded to 2 decimal places for presentation purposes.
expenses = [1234.5678, 987.6543, 2345.6789, 6789.1234]
rounded_expenses = [round(expense, 2) for expense in expenses]
print(rounded_expenses) Output:
[1234.57, 987.65, 2345.68, 6789.12]In this example, we use a list comprehension to iterate over the expenses list and apply the round() function to each expense, rounding it to 2 decimal places. The resulting rounded_expenses list contains the expenses rounded to 2 decimal places, ready for Sarah to include in her budget report.
Check out How to Count the Number of Digits in a Number in Python?
Conclusion
In this tutorial, I have explained how to round numbers to 2 decimal places in Python. I covered the round() method, f-string , math.floor(), decimal module and formatting with printf-style. We also discussed a real-time example.
You may also like to read:
- How to Split a Number into Digits in Python?
- How to Check if a String is Alphabet in Python?
- How to Check if a String Represents a Number with Decimal in Python?

I am Bijay Kumar, a Microsoft MVP in SharePoint. Apart from SharePoint, I started working on Python, Machine learning, and artificial intelligence for the last 5 years. During this time I got expertise in various Python libraries also like Tkinter, Pandas, NumPy, Turtle, Django, Matplotlib, Tensorflow, Scipy, Scikit-Learn, etc… for various clients in the United States, Canada, the United Kingdom, Australia, New Zealand, etc. Check out my profile.