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
🌐
mkaz.blog
mkaz.blog › working-with-python › string-formatting
Python String Formatting: Complete Guide - mkaz.blog
F-strings support comprehensive number formatting using format specifications after a colon: 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
Discussions

Pythonic way to show 2 decimal places in f-strings?

Do the second one, just don’t worry about rounding it. Let the formatting do the rounding for display.

More on reddit.com
🌐 r/learnpython
10
1
March 1, 2019
How to remove decimals in float?
If this is just for printing... f'{my_float:.6f}. If you actually need that level of precision, you're likely to run into rounding issues, but you could try something like this: int(my_float * (10**6)) / (10**6) More on reddit.com
🌐 r/learnpython
18
9
April 15, 2023
how do I limit the amount of decimal values stored in a float variable?
First, if you are not displaying it anywhere, do not do anything. There is no need to unnecessarily reduce accuracy. You are not hurting anything by having extra decimal places. But if you are and want to format it, well, that's just formatting like this https://appdividend.com/2022/06/23/how-to-format-float-values-in-python/ More on reddit.com
🌐 r/learnpython
6
1
November 20, 2022
Do you normally use string.format() or percentage (%) to format your Python strings?

Firstly, you can write e. g. {0:.2f} to specify a float with 2 decimals, see e. g. https://www.digitalocean.com/community/tutorials/how-to-use-string-formatters-in-python-3

Secondly, the best formatting method is f-strings, see e. g. https://www.blog.pythonlibrary.org/2018/03/13/python-3-an-intro-to-f-strings/

More on reddit.com
🌐 r/Python
130
75
June 3, 2018
🌐
Python Guides
pythonguides.com › python-print-2-decimal-places
How to Print Two Decimal Places in Python
December 22, 2025 - They were introduced in Python 3.6 and have completely changed how I write code. They are fast, readable, and allow you to format numbers directly within the string. # Monthly subscription cost for a streaming service in the USA monthly_fee = 14.991234 # Using an f-string to format to 2 decimal places formatted_fee = f"Your monthly subscription is: ${monthly_fee:.2f}" print(formatted_fee) # Output: Your monthly subscription is: $14.99
🌐
Cjtu
cjtu.github.io › spirl › python_str-formatting.html
3.10. String Formatting (Interactive) — Scientific Programming<br>In Real Life
We use three different format codes for the three numbers included in the string: ... The float format code rounding to 2 decimal places .2f.
🌐
Real Python
realpython.com › how-to-python-f-string-format-float
How to Format Floats Within F-Strings in Python – Real Python
March 18, 2026 - To use Python’s format specifiers in a replacement field, you separate them from the expression with a colon (:). As you can see, your float has been rounded to two decimal places. You achieved this by adding the format specifier .2f into the replacement field. The 2 is the precision, while the lowercase f is an example of a presentation type. You’ll see more of these later. Note: When you use a format specifier, you don’t actually change the underlying number. You only improve its display. Python’s f-strings also have their own mini-language that allows you to format your output in a variety of different ways.
🌐
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 - Also, using str.format() is simple, where you have to write within the curly braces how many places you want after the decimal followed by the variable name in the format function.
🌐
The Teclado Blog
blog.teclado.com › python-formatting-numbers-for-printing
Formatting Numbers for Printing in Python - The Teclado Blog
September 2, 2019 - To specify a level of precision, we need to use a colon (:), followed by a decimal point, along with some integer representing the degree of precision. We place this inside the curly braces for an f-string, after the value we want to format.
Find elsewhere
🌐
Reddit
reddit.com › r/learnpython › pythonic way to show 2 decimal places in f-strings?
r/learnpython on Reddit: Pythonic way to show 2 decimal places in f-strings?
March 1, 2019 -

I've got a number that needs to be rounded to 2 decimal places. Getting the round is easy, but if the number is a whole number or only has 1 digit beyond the decimal the rounding doesn't properly show 2 decimal places.

answer = 1
print(round(float(answer),2))

>> 1.0

I really like f-strings, so I would use this:

answer = 1
print(f"{round(float(answer),2):.2f}")

>> 1.00

Is there a neater or more readable method of doing this?

🌐
LinkedIn
linkedin.com › pulse › python-strings-format-mr-examples
Python Strings Format
May 18, 2023 - In Python, the .2f format specifier is used to format floating-point numbers as strings with two decimal places.
🌐
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 ...
🌐
OpenStax
openstax.org › books › introduction-python-programming › pages › 3-2-formatted-strings
3.2 Formatted strings - Introduction to Python Programming | OpenStax
March 13, 2024 - Use f-strings to simplify output with multiple values. Format numbers with leading zeros and fixed precision.
🌐
CodeRivers
coderivers.org › blog › python-format-string-decimal-places
Python Format String Decimal Places: A Comprehensive Guide - CodeRivers
April 13, 2025 - Here, {:.2f} is the format specifier within the curly braces. The colon (:) separates the field name from the format specifier, and 2 is the number of decimal places. f-Strings are a more concise and intuitive way to format strings in Python 3.6 and later.
🌐
EyeHunts
tutorial.eyehunts.com › home › how to display 2 decimal places in python | example code
How to display 2 decimal places in Python | Example code
January 11, 2023 - Use str.format() with “{:.2f}” as string and float as a number to display 2 decimal places in Python. Call print and it will display the...
🌐
Towards Data Science
towardsdatascience.com › home › programming › formatting strings and numbers in python
Formatting strings and numbers in python | Towards Data Science
June 27, 2021 - We can use the fortmat() string function in python to output the desired text in the order we want. ... Now extending the formatting using f keyword ( look at the piece above ) , lets try to use that in numbers, particularly involving decimals ...
🌐
Codecademy
codecademy.com › article › rounding-to-two-decimal-places-in-pythonn
Rounding to Two Decimal Places in Python | Codecademy
Let’s look at an example of how we can use str.format() to round a number to two decimal places: ... Let’s look at another approach for string formatting. In Python, the % operator, also called modulus operator, We can use this operator ...
🌐
GeeksforGeeks
geeksforgeeks.org › precision-handling-python
Precision Handling in Python - GeeksforGeeks
August 9, 2024 - Python provides for managing precise data and decimal points, the round() function is used to round a number to a specified number of decimal places. Alternatively, string formatting options, such as the f-string syntax or the format() method, allow ...
🌐
W3Schools
w3schools.com › python › python_string_formatting.asp
Python String Formatting
To format values in an f-string, add placeholders {}, a placeholder can contain variables, operations, functions, and modifiers to format the value. ... A placeholder can also include a modifier to format the value.
🌐
GeeksforGeeks
geeksforgeeks.org › python › how-to-get-two-decimal-places-in-python
How to get two decimal places in Python - GeeksforGeeks
July 23, 2025 - Python format() function is an inbuilt function used to format strings. Unlike f-string, it explicitly takes the expression as arguments. ... The % operator can also be used to get two decimal places in Python.
🌐
Linux find Examples
queirozf.com › entries › python-number-formatting-examples
Python number formatting examples
August 2, 2023 - Example: truncate to 2 decimal places in f-string · num = 1.12745 formatted = f"{num:.2f}" formatted # >>> '1.13' In some Python versions such as 2.6 and 3.0, you must specify positional indexes in the format string: # ValueError in python 2.6 and 3.0 a=1 b=2 "{}-{}".format(a,b) # NO ERROR in any python version "{0}-{1}".format(a,b) # >>> "1-2" Python 3 docs: Format Specification Mini Language ·
🌐
freeCodeCamp
freecodecamp.org › news › 2f-in-python-what-does-it-mean
%.2f in Python – What does it Mean?
June 22, 2022 - Note that the %f formatter must be nested inside quotation marks, and should be separated from the floating number which it is formatting by a modulo operator (%): "%f" % floatNumber. Let's take a look at another example. floatNumber = 1.9876 print("%.1f" % floatNumber) # 2.0 · In the code above, we added .1 between % and f in the %f operator...