As a developer working on numerous projects across the USA, I recently faced an issue where I needed to format currency values with a specific number of decimal places for our financial reports. After researching various string formatting techniques, I found that using f-strings is an efficient and readable way to format decimal places. I will help you learn how to format decimal places in Python using f-strings in this tutorial with examples.
f-Strings in Python
F-strings, introduced in Python 3.6, provide a concise and expressive way to embed expressions inside string literals for formatting. They allow you to include variables, expressions, and even function calls directly within the string.
Read How to Extract Numbers from a String in Python?
Format Decimal Places with f-Strings in Python
To format a decimal number with a specific number of decimal places using f-strings in Python, you can use the .nf syntax, where n represents the desired number of decimal places. Here’s an example:
revenue = 1234.5678
print(f"The company's revenue is ${revenue:.2f}")Output:
The company's revenue is $1234.57I have executed the above example code and added the screenshot below.

This example {revenue:.2f} specifies that the revenue variable should be formatted as a floating-point number with two decimal places.
Read How to Split a Long String into Multiple Lines in Python?
Example: Format Currency Values
Let’s consider a real-world scenario where we need to format currency values for a financial report. Suppose we have a list of transactions for a US-based company:
transactions = [
{"customer": "John Smith", "amount": 124.99},
{"customer": "Emma Johnson", "amount": 50.75},
{"customer": "Michael Brown", "amount": 89.50},
{"customer": "Olivia Davis", "amount": 200.00}
]To format the transaction amounts with two decimal places and a dollar sign, we can use f-strings as follows:
for transaction in transactions:
customer = transaction["customer"]
amount = transaction["amount"]
print(f"{customer}: ${amount:.2f}")Output:
John Smith: $124.99
Emma Johnson: $50.75
Michael Brown: $89.50
Olivia Davis: $200.00I have executed the above example code and added the screenshot below.

By using {amount:.2f}, we ensure that each transaction amount is displayed with exactly two decimal places, making the output consistent and readable.
Check out How to Pad a String with Zeros in Python?
Advanced Formatting with f-Strings
F-strings offer additional formatting options that can be useful when working with decimal places:
1. Thousands Separator
To format large numbers with a thousand separator, you can use the , symbol within the f-string. For example:
revenue = 1234567.89
print(f"The company's annual revenue is ${revenue:,.2f}")Output:
The company's annual revenue is $1,234,567.89I have executed the above example code and added the screenshot below.

Read How to Find the Last Occurrence of a Substring in a String Using Python?
2. Percentage Formatting
If you need to format decimal numbers as percentages, you can use the % symbol. Here’s an example:
growth_rate = 0.0875
print(f"The company's growth rate is {growth_rate:.2%}")Output:
The company's growth rate is 8.75%Check out How to Iterate Through a String in Python?
Conclusion
In this tutorial, I have explained how to format decimal places in Python using f-strings. I discussed f-strings in Python, how to format decimal places with f-strings , and a real-world example. I also discussed some advanced formatting with f-strings.
You may also like to read:
- How to Add Characters to a String in Python?
- How to Escape Curly Braces in Python Format Strings?
- How to Parse a String 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.