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
๐ŸŒ
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 - 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.
People also ask

How can I customize decimal places with %.2f?
You can change the number before โ€œfโ€. For example, %.3f gives 3 decimal places and %.1f gives 1 decimal place. Python formats the number accordingly.
๐ŸŒ
pwskills.com
pwskills.com โ€บ blog โ€บ python โ€บ what does %.2f mean in python?
What Does %.2f Mean In Python? Format Float To 2 Decimal Places ...
What does "%.2f" mean in Python?
โ€œ%.2fโ€ tells Python to format a floating-point number with exactly 2 digits after the decimal. It rounds the value if needed and outputs a clean, consistent numeric format. This is commonly used in reports, billing systems, financial calculations, and formatted print statements.
๐ŸŒ
pwskills.com
pwskills.com โ€บ blog โ€บ python โ€บ what does %.2f mean in python?
What Does %.2f Mean In Python? Format Float To 2 Decimal Places ...
What does .2f do in Python?
โ€œ.2fโ€ specifies the precision part of a format string, ensuring the float shows only two decimal places. It applies rounding automatically and works with print(), f-strings, and format().
๐ŸŒ
pwskills.com
pwskills.com โ€บ blog โ€บ python โ€บ what does %.2f mean in python?
What Does %.2f Mean In Python? Format Float To 2 Decimal Places ...
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ how-to-get-two-decimal-places-in-python
How to get two decimal places in Python - GeeksforGeeks
July 23, 2025 - ... The decimal module provides ... 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....
๐ŸŒ
w3resource
w3resource.com โ€บ python-exercises โ€บ string โ€บ python-data-type-string-exercise-30.php
Python: Print the following floating numbers upto 2 decimal places - w3resource
... # Define a variable 'x' and ... line for spacing. print() # Print the original value of 'x' with a label. print("Original Number: ", x) # Format the value of 'x' to two decimal places and print it with a lab...
๐ŸŒ
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 - Learn how to use round(), string formatting, f-strings, format(), math module, and % operator for .2f formatting in Python. Master precise number handling!
๐ŸŒ
Python Guides
pythonguides.com โ€บ python-print-2-decimal-places
How to Print Two Decimal Places in Python
December 22, 2025 - Master the art of formatting Python floats. Learn 5 easy methods to print 2 decimal places in Python using f-strings, format(), and the round() function.
๐ŸŒ
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.
Find elsewhere
๐ŸŒ
PW Skills
pwskills.com โ€บ blog โ€บ python โ€บ what does %.2f mean in python?
What Does %.2f Mean In Python? Format Float To 2 Decimal Places Explained
October 30, 2025 - In Python, %.2f formats a float to 2 decimal places. Learn what %.2f means, how to use .2f in print statements, f-strings, and format(), with simple examples.
๐ŸŒ
Codecademy
codecademy.com โ€บ article โ€บ rounding-to-two-decimal-places-in-pythonn
Rounding to Two Decimal Places in Python | Codecademy
Learn how to round a number in Python to two decimal places using the round, string formatting, and modulus operators.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ precision-handling-python
Precision Handling in Python - GeeksforGeeks
December 19, 2025 - Explanation: quantize(Decimal('0.00')) formats the number to exactly 2 decimal places.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ how-to-round-floating-value-to-two-decimals-in-python
How to Round Floating Value to Two Decimals in Python - GeeksforGeeks
July 23, 2025 - from decimal import Decimal, ... specifies that we want to round to two decimal places n2 = n1.quantize(Decimal('0.01'), rounding=ROUND_HALF_UP) print(n2) ......
๐ŸŒ
freeCodeCamp
freecodecamp.org โ€บ news โ€บ 2f-in-python-what-does-it-mean
%.2f in Python โ€“ What does it Mean?
June 22, 2022 - floatNumber = 1.9876 print("%.2f" % floatNumber) # 1.99 ยท As expected, the floating point number (1.9876) was rounded up to two decimal places โ€“ 1.99.
๐ŸŒ
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.
๐ŸŒ
Linux find Examples
queirozf.com โ€บ entries โ€บ python-number-formatting-examples
Python number formatting examples
August 2, 2023 - Drop digits after the second decimal place (if there are any). import re # see the notebook for a generalized version def truncate(num): return re.sub(r'^(\d+\.\d{,2})\d*$',r'\1',str(num)) truncate(8.499) # >>> '8.49' truncate(8.49) # >>> '8.49' truncate(8.4) # >>> '8.4' truncate(8.0) # >>> '8.0' truncate(8) # >>> '8'
๐ŸŒ
W3Schools
w3schools.com โ€บ python โ€บ python_string_formatting.asp
Python String Formatting
Add a placeholder where you want to display the price: price = 49 txt = "The price is {} dollars" print(txt.format(price)) Try it Yourself ยป ยท You can add parameters inside the curly brackets to specify how to convert the value: Format the price to be displayed as a number with two decimals: txt = "The price is {:.2f} dollars" Try it Yourself ยป
๐ŸŒ
PythonHow
pythonhow.com โ€บ how โ€บ limit-floats-to-two-decimal-points
Here is how to limit floats to two decimal points in Python
x = 3.14159265 # Format x as a string with two decimal points y = "{:.2f}".format(x) print(y) # Output: "3.14"The format function takes a format string as the first argument and the value to format as the second argument.
Top answer
1 of 16
2330

You are running into the old problem with floating point numbers that not all numbers can be represented exactly. The command line is just showing you the full floating point form from memory.

With floating point representation, your rounded version is the same number. Since computers are binary, they store floating point numbers as an integer and then divide it by a power of two so 13.95 will be represented in a similar fashion to 125650429603636838/(2**53).

Double precision numbers have 53 bits (16 digits) of precision and regular floats have 24 bits (8 digits) of precision. The floating point type in Python uses double precision to store the values.

For example,

>>> 125650429603636838/(2**53)
13.949999999999999

>>> 234042163/(2**24)
13.949999988079071

>>> a = 13.946
>>> print(a)
13.946
>>> print("%.2f" % a)
13.95
>>> round(a,2)
13.949999999999999
>>> print("%.2f" % round(a, 2))
13.95
>>> print("{:.2f}".format(a))
13.95
>>> print("{:.2f}".format(round(a, 2)))
13.95
>>> print("{:.15f}".format(round(a, 2)))
13.949999999999999

If you are after only two decimal places (to display a currency value, for example), then you have a couple of better choices:

  1. Use integers and store values in cents, not dollars and then divide by 100 to convert to dollars.
  2. Or use a fixed point number like decimal.
2 of 16
838

There are new format specifications, String Format Specification Mini-Language:

You can do the same as:

"{:.2f}".format(13.949999999999999)

Note 1: the above returns a string. In order to get as float, simply wrap with float(...):

float("{:.2f}".format(13.949999999999999))

Note 2: wrapping with float() doesn't change anything:

>>> x = 13.949999999999999999
>>> x
13.95
>>> g = float("{:.2f}".format(x))
>>> g
13.95
>>> x == g
True
>>> h = round(x, 2)
>>> h
13.95
>>> x == h
True
๐ŸŒ
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