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
Discussions

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 use the float() command to create 2 decimal places instead of one in a product of 2 numbers [the product is dollar amount]
You generally don't round until you go to display the value. You can use round for that, but since you just want to display it with two digits, you can use string formatting . In your case, something like print(f'{totalPay:.2f}'). .2f is the format specifier, saying round the float (f) to two decimal places (.2). More on reddit.com
๐ŸŒ r/learnpython
9
7
January 28, 2020
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
How do I put commas between numbers?
Say this is your number. a_number = 1234567890 You can add the commas like this print(format(a_number, ",")) or like this. print(f"{a_number:,}") Either way, what you're doing here is using a "format specifier" to create a string from the number formatted the way you like. A , means to format your integer or floating point number with commas every third numbers to the left of the decimal. You can see the full list of format specifiers here in the documentation (though TBH it's a bit hard to find what you need in it). More on reddit.com
๐ŸŒ r/learnpython
7
11
October 24, 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.
๐ŸŒ
Bobby Hadz
bobbyhadz.com โ€บ blog โ€บ python-format-number-thousands-separator-2-decimals
Format number with comma as thousands separator in Python | bobbyhadz
April 9, 2024 - 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
๐ŸŒ
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 ...
๐ŸŒ
Python
docs.python.org โ€บ 3 โ€บ library โ€บ decimal.html
decimal โ€” Decimal fixed-point and floating-point arithmetic
A: The quantize() method rounds to a fixed number of decimal places. If the Inexact trap is set, it is also useful for validation: >>> TWOPLACES = Decimal(10) ** -2 # same as Decimal('0.01')
Find elsewhere
๐ŸŒ
YouTube
youtube.com โ€บ watch
Python 74: Formatting a floating point number to 2 decimal places using the format() method - YouTube
Displaying/formatting a floating point number to 2 decimal places using the format() method. .2f specifies two decimal places, the number is displayed round...
Published ย  October 15, 2024
๐ŸŒ
mkaz.blog
mkaz.blog โ€บ working-with-python โ€บ string-formatting
Python String Formatting: Complete Guide
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 ยท
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ how-to-get-two-decimal-places-in-python
How to get two decimal places in Python - GeeksforGeeks
July 23, 2025 - And the final step includes dividing the number by 100. ... The decimal module provides various functions that can be used to get two decimal places of a float value. The Decimal() function is used to convert the float-point value to a decimal object. Then the quantize() function is used to set the decimal to a specific format.
๐ŸŒ
CodeRivers
coderivers.org โ€บ blog โ€บ python-format-number-with-commas
Python Format Number with Commas: A Comprehensive Guide - CodeRivers
April 5, 2025 - 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 ...
๐ŸŒ
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.
๐ŸŒ
AskPython
askpython.com โ€บ home โ€บ how to format a number to 2 decimal places in python?
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.
๐ŸŒ
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) )
๐ŸŒ
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.
๐ŸŒ
DataCamp
datacamp.com โ€บ tutorial โ€บ python-round-to-two-decimal-places
How to Round to 2 Decimal Places in Python | DataCamp
August 8, 2024 - Learn how to round a number to two decimal places in Python for improved precision using techniques like round(), format(), and string formatting techniques.
๐ŸŒ
Sololearn
sololearn.com โ€บ en โ€บ Discuss โ€บ 3288381 โ€บ how-to-round-to-2-decimal-places-in-python
How to round to 2 decimal places in python | Sololearn: Learn to code for FREE!
Yes, you can use the round() function in Python to round a float to a specific number of decimal places. In your case, you can use round(number, 2) to round the number to 2 decimal places.