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
๐ŸŒ
Python
docs.python.org โ€บ 3 โ€บ library โ€บ decimal.html
decimal โ€” Decimal fixed-point and floating-point arithmetic
Decimals can be formatted (with format() built-in or f-strings) in fixed-point or scientific notation, using the same formatting syntax (see Format Specification Mini-Language) as builtin float type:
๐ŸŒ
W3Schools
w3schools.com โ€บ python โ€บ python_string_formatting.asp
Python String Formatting
The function does not have to be a built-in Python method, you can create your own functions and use them: ... def myconverter(x): return x * 0.3048 txt = f"The plane is flying at a {myconverter(30000)} meter altitude" print(txt) Try it Yourself ยป ยท At the beginning of this chapter we explained how to use the .2f modifier to format a number into a fixed point number with 2 decimals.
Discussions

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
python - Limiting floats to two decimal points - Stack Overflow
Note that if you try to use this method to print out a number such as 1.00000 it will only print out 1.0, regardless of how many decimal points you specify. 2019-08-03T16:36:04.177Z+00:00 ... Let me give an example in Python 3.6's f-string/template-string format, which I think is beautifully neat: More on stackoverflow.com
๐ŸŒ stackoverflow.com
Python Decimals format - Stack Overflow
What is a good way to format a python decimal like this way? 1.00 --> '1' 1.20 --> '1.2' 1.23 --> '1.23' 1.234 --> '1.23' 1.2345 --> '1.23' More on stackoverflow.com
๐ŸŒ stackoverflow.com
Logging โ†’ format decimal places?
Thereโ€™s is sometimes a good reason to pass values the other way, if they are expensive to compute (see here). But if you already have crmTime around I think this is fine ยท Alternatively, the formatting for the logging message is the same as the % style, you can use %.4f there too More on discuss.python.org
๐ŸŒ discuss.python.org
0
0
November 8, 2023
๐ŸŒ
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.
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
Find elsewhere
๐ŸŒ
Python.org
discuss.python.org โ€บ python help
Logging โ†’ format decimal places? - Python Help - Discussions on Python.org
November 8, 2023 - Thereโ€™s is sometimes a good reason to pass values the other way, if they are expensive to compute (see here). But if you already have crmTime around I think this is fine ยท Alternatively, the formatting for the logging message is the same as the % style, you can use %.4f there too
๐ŸŒ
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.
๐ŸŒ
Python
docs.python.org โ€บ 3 โ€บ library โ€บ string.html
string โ€” Common string operations
For Decimal, the rounding mode of the current context will be used. The available presentation types for complex are the same as those for float ('%' is not allowed). Both the real and imaginary components of a complex number are formatted as ...
๐ŸŒ
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 ...
๐ŸŒ
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 - 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. Hereโ€™s the official Python documentation to help you understand decimal in Python.
๐ŸŒ
Python Reference
python-reference.readthedocs.io โ€บ en โ€บ latest โ€บ docs โ€บ functions โ€บ format.html
format โ€” Python Reference (The Right Way) 0.1 documentation
Then if -4 <= exp < p, the number is formatted with presentation type โ€˜fโ€™ and precision p-1-exp. Otherwise, the number is formatted with presentation type โ€˜eโ€™ and precision p-1. In both cases insignificant trailing zeros are removed from the significand, and the decimal point is also removed if there are no remaining digits following it.
๐ŸŒ
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 - To do this manually, you need to multiply the number by one hundred and append it with a percent sign (%) before displaying it with the required amount of decimal places. You can do all of this automatically by using the % presentation type ...
๐ŸŒ
mkaz.blog
mkaz.blog โ€บ working-with-python โ€บ string-formatting
Python String Formatting: Complete Guide
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
๐ŸŒ
freeCodeCamp
freecodecamp.org โ€บ news โ€บ 2f-in-python-what-does-it-mean
%.2f in Python โ€“ What does it Mean?
June 22, 2022 - The %f formatter is specifically used for formatting float values (numbers with decimals). We can use the %f formatter to specify the number of decimal numbers to be returned when a fl...
๐ŸŒ
Mooc
programming-25.mooc.fi โ€บ part-4 โ€บ 5-print-statement-formatting
Print statement formatting - Python Programming MOOC 2025
The format specifier .2f states that we want to display 2 decimals. The letter f at the end means that we want the variable to be displayed as a float, i.e.
๐ŸŒ
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.
๐ŸŒ
LabEx
labex.io โ€บ tutorials โ€บ python-how-to-format-decimal-output-in-python-421895
How to format decimal output in Python | LabEx
Learn essential techniques for formatting decimal numbers in Python, including precision control, rounding, and display methods for professional data presentation.
๐ŸŒ
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 ...
๐ŸŒ
TestMu AI Community
community.testmuai.com โ€บ ask a question
How can I format a decimal to always show 2 decimal places in Python? - TestMu AI Community
November 28, 2024 - How can I format a decimal to always show 2 decimal places in Python? I want to display values like: - 49 as 49.00 - 54.9 as 54.90 Regardless of the number of decimal places, I want to ensure that the decimal is always displayed with 2 decimal places. This is for displaying monetary values, ...