You should use the new format specifications to define how your value should be represented:

>>> from math import pi  # pi ~ 3.141592653589793
>>> '{0:.2f}'.format(pi)
'3.14'

The documentation can be a bit obtuse at times, so I recommend the following, easier readable references:

  • the Python String Format Cookbook: shows examples of the new-style .format() string formatting
  • pyformat.info: compares the old-style % string formatting with the new-style .format() string formatting

Python 3.6 introduced literal string interpolation (also known as f-strings) so now you can write the above even more succinct as:

>>> f'{pi:.2f}'
'3.14'
Answer from BioGeek on Stack Overflow
🌐
Bobby Hadz
bobbyhadz.com β€Ί blog β€Ί python-format-number-thousands-separator-2-decimals
Format number with comma as thousands separator in Python | bobbyhadz
The same approach can be used to format a number with thousands separator to 2 decimal places. ... Copied! my_float = 489985.456789 # βœ… Format a number with comma as thousands separator rounded to 2 decimals result = f'{my_float:,.2f}' print(result) # πŸ‘‰οΈ 489,985.46 # βœ… Format a number with comma as thousands separator rounded to 3 decimals result = f'{my_float:,.3f}' print(result) # πŸ‘‰οΈ 489,985.457
Discussions

Format a number with comma separators and round to 2 decimal places in Python 2? - Stack Overflow
I'm sure this must be a duplicate but I can't find a clear answer on SO. How do I output 2083525.34561 as 2,083,525.35 in Python 2? I know about: "{0:,f}".format(2083525.34561) which outputs co... More on stackoverflow.com
🌐 stackoverflow.com
python - Add commas into number string - Stack Overflow
I have a value running through my program that puts out a number rounded to 2 decimal places at the end, like this: print ("Total cost is: ${:0.2f}".format(TotalAmount)) Is there a way to More on stackoverflow.com
🌐 stackoverflow.com
Formatting commas with 2 decimals PYTHON - Stack Overflow
I am trying to format a number to have commas and two decimal points at the end of it like: 100,000.00 This is what I have tried, but it won't work because I can't use these number formats on each ... More on stackoverflow.com
🌐 stackoverflow.com
How to format to two decimal places python
There are several ways to do it, string formatting being one, but round is the easiest: String formatting: print('%.2f' % number) round: float_number = round(number, 2) More on reddit.com
🌐 r/learnprogramming
4
1
April 29, 2021
🌐
Python Guides
pythonguides.com β€Ί python-format-number-with-commas
How To Format Numbers With Commas In Python?
December 22, 2025 - The first method to format a number with commas and 2 decimal places in Python is by using the f-strings method.
🌐
Linux find Examples
queirozf.com β€Ί entries β€Ί python-number-formatting-examples
Python number formatting examples
August 2, 2023 - Truncate float at 2 decimal places Β· Left padding with zeros Β· Right padding with zeros Β· Use commas as thousands separator Β· Interpolate variable with f-strings Β· ValueError: zero length field name in format Β· All examples assume Python 3+ See the difference between truncating and rounding ...
Find elsewhere
🌐
Delft Stack
delftstack.com β€Ί home β€Ί howto β€Ί python β€Ί python format number with commas
How to Format Number With Commas in Python | Delft Stack
March 13, 2025 - import locale locale.setlocale... using locale.setlocale(locale.LC_ALL, ''). The format_string function then formats the number with commas and limits the decimal places to two....
🌐
CodeRivers
coderivers.org β€Ί blog β€Ί python-format-number-with-commas
Python Format Number with Commas: A Comprehensive Guide - CodeRivers
February 22, 2026 - The colon (:) starts the format specifier, and the comma (``,) inside it indicates that the number should be formatted with a comma as a thousands separator. If you want to format a floating-point number, you can also specify the number of decimal places. For example: float_number = 123456.789 ...
🌐
Program Arcade Games
programarcadegames.com β€Ί index.php
Program Arcade Games With Python And Pygame
It means a total field width of five, including the decimal and the two digits after. Here's the output: ... Danger! The above code has a mistake that is very common when working with financial transactions. Can you spot it? Try spotting it with the expanded code example below: cost1 = 3.07 tax1 = cost1 * 0.06 total1 = cost1 + tax1 print("Cost: ${0:5.2f}".format(cost1) ) print("Tax: {0:5.2f}".format(tax1) ) print("------------") print("Total: ${0:5.2f}".format(total1) ) cost2 = 5.07 tax2 = cost2 * 0.06 total2 = cost2 + tax2 print() print("Cost: ${0:5.2f}".format(cost2) ) print("Tax: {0:5.2f}".format(tax2) ) print("------------") print("Total: ${0:5.2f}".format(total2) ) print() grand_total = total1 + total2 print("Grand total: ${0:5.2f}".format(grand_total) )
🌐
mkaz.blog
mkaz.blog β€Ί working-with-python β€Ί string-formatting
Python String Formatting: Complete Guide - mkaz.blog
value = 1234.5678 # Basic decimal places print(f"Two decimals: {value:.2f}") # 1234.57 print(f"No decimals: {value:.0f}") # 1235 print(f"With sign: {value:+.2f}") # +1234.57 # Padding and alignment print(f"Right aligned: {value:10.2f}") # 1234.57 print(f"Left aligned: {value:<10.2f}") # 1234.57 print(f"Center aligned: {value:^10.2f}") # 1234.57 print(f"Zero padded: {value:010.2f}") # 001234.57 # Thousands separator print(f"With commas: {value:,.2f}") # 1,234.57 # Percentage ratio = 0.857 print(f"Percentage: {ratio:.1%}") # 85.7% # Scientific notation big_number = 1500000 print(f"Scientific: {big_number:.2e}") # 1.50e+06 # Different bases num = 255 print(f"Hex: {num:x}") # ff print(f"Binary: {num:b}") # 11111111 print(f"Octal: {num:o}") # 377 Β·
🌐
AskPython
askpython.com β€Ί python β€Ί built-in-methods β€Ί format-2-decimal-places
How to Format a Number to 2 Decimal Places in Python? - AskPython
February 27, 2023 - Here β€œ{:.2f}” is a string where we have mentioned .2f, which means 2 digits after the decimal in the float number. Then we provide our float value on which the action will take place in the format function. In the result, we are getting the same result using two different ways. You can check The Python float() Method for more knowledge on the float method.
🌐
AskPython
askpython.com β€Ί python β€Ί string β€Ί adding-commas-into-number-string
Adding commas into number string - AskPython
February 27, 2023 - To round the float format number with commas as thousands separators we use {:,.2f}. The digits beyond two places after the decimal get ignored. If we want to round the number to 3 places, we can do it by replacing 2 with 3. num = 2232890.82728 ...
🌐
Python Guides
pythonguides.com β€Ί python-print-2-decimal-places
How to Print Two Decimal Places in Python
December 22, 2025 - Inside the curly braces, the :.2f is the magic part. The colon starts the format specifier, the .2 indicates two decimal places, and the f tells Python to treat the value as a float.
🌐
Ceos3c
ceos3c.com β€Ί home β€Ί python β€Ί python round 2 decimals with floats – super easy method
Python Round 2 Decimals with Floats - Super Easy Method
October 5, 2022 - For example, if we wanted to round the number 4.738 to two decimal places, we would write: ... This is the easiest, most straightforward way to round 2 decimals with Floats in Python.
🌐
Analytics Vidhya
analyticsvidhya.com β€Ί home β€Ί 6 ways to round floating value to two decimals in python
6 Ways to Round Floating Value to Two Decimals in Python
November 4, 2024 - By applying the .2f format specifier within the format() method and using the "{:.2f}" format string, the number is formatted to have two decimal places. The resulting formatted_number is then printed, which outputs 3.14 ...
🌐
GeeksforGeeks
geeksforgeeks.org β€Ί python β€Ί formatting-integer-column-of-dataframe-in-pandas
Formatting float column of Dataframe in Pandas - GeeksforGeeks
October 3, 2025 - '{:,.2f}'.format: Formats numbers with commas and 2 decimal places. .apply(lambda x: ...): Applies the formatting to each element in the column. Large numbers can be hard to interpret.
🌐
Sololearn
sololearn.com β€Ί en β€Ί Discuss β€Ί 3288381 β€Ί how-to-round-to-2-decimal-places-in-python
How to round to 2 decimal places in python
sl_scroll_/de/Discuss/2689918/i-made-a-bmi-calculator-in-python-and-youa-are-supposed-to-write-the-height-in-meter-i-want-whenever-you-write-the-height-in-cePending