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.
Answer from Rex Logan on Stack Overflow
๐ŸŒ
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.
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
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
January 15, 2018
python - How can I format a decimal to always show 2 decimal places? - Stack Overflow
Consider r = 1; "%s" % r; r = (1, ... r = (1,2 ); "%s" % (r,). As such, most sophisticated coding styles in python use the unconditional tuple now (and Python 3 deprecated the entire method of string formatting as error prone). 2010-01-04T01:06:13.513Z+00:00 ... I suppose you're probably using the Decimal() objects from the decimal module? (If you need exactly two digits of precision beyond the decimal point with arbitrarily large numbers, you definitely ... 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
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
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 ...
๐ŸŒ
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
๐ŸŒ
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 % operator can also be used to get two decimal places in Python. It is a more traditional approach which makes the use of string formatting technique. ... Python math module provides various function that can be used to perform various ...
๐ŸŒ
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?
January 15, 2018 -

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?

Find elsewhere
๐ŸŒ
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 ...
๐ŸŒ
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!
August 15, 2024 - 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.
๐ŸŒ
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 - The f indicates that the value being inserted is a floating-point number. Placeholder Replacement: When you use โ€œ%.2fโ€ in a format string and apply the % operator with a float value, Python replaces โ€œ%.2fโ€ with the float value formatted to display two decimal places.
๐ŸŒ
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')
๐ŸŒ
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 ...
๐ŸŒ
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 ยป
๐ŸŒ
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 - It is pretty simple by using %f formatter or str.format() with โ€œ{:.2f}โ€ as a string and float as a number. Letโ€™s take a look at the first method. The %f formatter is used to input float values or numbers with values after the decimal place.
๐ŸŒ
freeCodeCamp
freecodecamp.org โ€บ news โ€บ 2f-in-python-what-does-it-mean
%.2f in Python โ€“ What does it Mean?
June 22, 2022 - So %.2f means to round up to two decimal places. You can play around with the code to see what happens as you change the number in the formatter. Another formatting method we can use with floating point numbers in Python is the %d formatter.
๐ŸŒ
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) ......
๐ŸŒ
Real Python
realpython.com โ€บ how-to-python-f-string-format-float
How to Format Floats Within F-Strings in Python โ€“ Real Python
April 24, 2024 - 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.
๐ŸŒ
PythonHow
pythonhow.com โ€บ how โ€บ limit-floats-to-two-decimal-points
Here is how to limit floats to two decimal points in Python
Here is an example of how to use ... 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....
๐ŸŒ
TutorialsPoint
tutorialspoint.com โ€บ how-to-round-down-to-2-decimals-a-float-using-python
How to round down to 2 decimals a float using Python?
August 29, 2023 - # input floating-point number ... to be followed to perform the desired task -. Create a variable to store the input floating-point number. Use the format() function (It gives back a formatted version of the input value that has been specified by the format specifier) to round ...