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 2 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

python - How can I format a decimal to always show 2 decimal places? - Stack Overflow
Consider r = 1; "%s" % r; r = (1, ... 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
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 13, 2018
How to format numbers/text to 2 decimal places?
I am using Elefront to generate text objects from a spreadsheet. I need these numbers to be displayed at 2 decimal places. They currently go from 0 to MANY decimal places. I can’t find a way to format numeric output to just 2 decimals. Feeling dumb - it could be Excel - or Grasshopper - or ... More on discourse.mcneel.com
🌐 discourse.mcneel.com
1
0
April 10, 2018
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
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 13, 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
In Python, the % operator, also called modulus operator, We can use this operator for string formatting to round values to a specific number of decimal places. Known as old-style or printf-style formatting, this approach uses format specifiers ...
🌐
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.
🌐
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 this case, it’s 2, meaning you want to display two decimal places. 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
What methods should be used? 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.
🌐
Python
docs.python.org › 3 › library › string.html
string — Common string operations
An arg_name is treated as a number if a call to str.isdecimal() on the string would return true. If the numerical arg_names in a format string are 0, 1, 2, … in sequence, they can all be omitted (not just some) and the numbers 0, 1, 2, … will be automatically inserted in that order.
🌐
Python documentation
docs.python.org › 3 › tutorial › inputoutput.html
7. Input and Output — Python 3.14.3 documentation
>>> yes_votes = 42_572_654 >>> total_votes = 85_705_149 >>> percentage = yes_votes / total_votes >>> '{:-9} YES votes {:2.2%}'.format(yes_votes, percentage) ' 42572654 YES votes 49.67%' Notice how the yes_votes are padded with spaces and a negative sign only for negative numbers. The example also prints percentage multiplied by 100, with 2 decimal places and followed by a percent sign (see Format Specification Mini-Language for details).
🌐
W3Schools
w3schools.com › python › ref_func_round.asp
Python round() Function
Python Examples Python Compiler Python Exercises Python Quiz Python Challenges Python Server Python Syllabus Python Study Plan Python Interview Q&A Python Bootcamp Python Certificate Python Training ... The round() function returns a floating ...
🌐
Mooc
programming-25.mooc.fi › part-4 › 5-print-statement-formatting
Print statement formatting - Python Programming MOOC 2025
By default the number is quite ... curly brackets of the variable expression. Let's add a colon character and a format specifier after the variable name: ... The format specifier .2f states that we want to display 2 decimals....