The comments state the objective is to print to 2 decimal places.

There's a simple answer for Python 3:

>>> num=3.65
>>> "The number is {:.2f}".format(num)
'The number is 3.65'

or equivalently with f-strings (Python 3.6+):

>>> num = 3.65
>>> f"The number is {num:.2f}"
'The number is 3.65'

As always, the float value is an approximation:

>>> "{}".format(num)
'3.65'
>>> "{:.10f}".format(num)
'3.6500000000'
>>> "{:.20f}".format(num)
'3.64999999999999991118'

I think most use cases will want to work with floats and then only print to a specific precision.

Those that want the numbers themselves to be stored to exactly 2 decimal digits of precision, I suggest use the decimal type. More reading on floating point precision for those that are interested.

Answer from Andrew E on Stack Overflow
🌐
EyeHunts
tutorial.eyehunts.com › home › python float precision to 3
Python float precision to 3 - Tutorial - By EyeHunts
July 10, 2023 - In Python, the float type does not inherently have a fixed precision. The precision of a float is determined by the floating-point representation used by the underlying hardware, which is typically based on the IEEE 754 standard.
🌐
Python documentation
docs.python.org › 3 › tutorial › floatingpoint.html
15. Floating-Point Arithmetic: Issues and Limitations — Python 3.14.6 documentation
For use cases which require exact ... and high-precision applications. Another form of exact arithmetic is supported by the fractions module which implements arithmetic based on rational numbers (so the numbers like 1/3 can be represented exactly). If you are a heavy user of floating-point operations you should take a look at the NumPy package and many other packages for mathematical and statistical operations supplied by the SciPy project. See <https://scipy.org>. Python provides tools that may help ...
Discussions

python - Limiting floats to two decimal points - Stack Overflow
But note that for Python versions above 3 (e.g. 3.2 or 3.3), option two is preferred. For more information on option two, I suggest this link on string formatting from the Python documentation. And for more information on option one, this link will suffice and has information on the various flags. Reference: Convert floating point number to a certain precision... More on stackoverflow.com
🌐 stackoverflow.com
[Python] Adding floating point number causes precision issues for some numbers but not othera.
See here . This is specific to a widely-used way of representing decimal numbers. This isn't specific to Python. More on reddit.com
🌐 r/learnprogramming
8
0
January 9, 2024
How to truncate a float?
It's worth keeping in mind that the internal representation of floating point numbers in all the main programming languages including Python is not decimal but binary. This means that if you use string processing to set the number of decimal places then convert it back to a float, you'll lose the decimal precision anyway. e.g.: >>> a = float("0.1") >>> b = float("0.2") >>> a + b 0.30000000000000004 As has already been pointed out, you normally set the precision when converting to a string for displaying the result, so it's best to use the format() function or f-strings for output. If for some reason, you wish to maintain exact base-10 decimal precision throughout the calculations, because you're writing a finance program or something, then it's worth learning about the features of Python's decimal library. More on reddit.com
🌐 r/learnpython
5
2
July 1, 2022
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
🌐
Finxter
blog.finxter.com › 5-best-ways-to-round-float-to-3-decimals-in-python
5 Best Ways to Round Float to 3 Decimals in Python – Be on the Right Side of Change
This code leverages string formatting with the format specifier {:.3f} to convert and round the float to three decimal places. This method is especially useful when the rounded value needs to be a string, such as in formatted output or concatenated messages. For financial and other high-precision applications, rounding floats using Python’s Decimal module is suitable as it provides decimal floating point arithmetic.
🌐
Medium
medium.com › @goldengrisha › understanding-floating-point-precision-issues-in-python-a-practical-guide-5e17b2f14057
Understanding Floating-Point Precision Issues in Python: A Practical Guide | by Gregory Kovalchuk | Medium
September 25, 2024 - Here, adding `0.1` and `0.2` should yield `0.3`, but instead, we get `0.30000000000000004`. The reason is that neither `0.1` nor `0.2` has an exact binary representation, and the small rounding errors accumulate when the values are added. Let’s consider a more complex scenario, one involving a physics simulation where we calculate forces. Suppose we have the following Python function to compute a force value `v(k, n)` and sum it over multiple iterations: def v(k: int, n: int) -> float: return 1 / (k * (n + 1) ** (2 * k)) def doubles(maxk: int, maxn: int) -> float: total = 0 old_total = 0 for k in range(1, maxk + 1): local_total = 0 for n in range(1, maxn + 1): local_total += v(k, n) old_total += v(k, n) # Updates old_total within the loop total += local_total return total
Top answer
1 of 16
2332

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
🌐
GeeksforGeeks
geeksforgeeks.org › precision-handling-python
Precision Handling in Python - GeeksforGeeks
August 9, 2024 - The integral value of number is : 3 The smallest integer greater than number is : 4 The greatest integer smaller than number is : 3 ... In Python, we can handle precision values using Decimal Module. In this example, we will see How to Limit Float to Two Decimal Points in Python.
Find elsewhere
🌐
Luc
anh.cs.luc.edu › handsonPythonTutorial › float.html
1.14. Decimals, Floats, and Floating Point Arithmetic — Hands-on Python Tutorial for Python 3
Try each in the Shell (and guess the resulting type): [1] ... Exponentiation is finding powers. In mathematical notation, (3)(3)(3)(3)=34. In Python there is no fancy typography with raised exponent symbols like the 4, so Python uses ** before a power: Try in the Shell:
🌐
Shiksha
shiksha.com › home › it & software › it & software articles › programming articles › precision handling in python
Precision Handling in Python - Shiksha Online
October 31, 2022 - The format() function in python can be used to format a float value for precision based on the format specifier. ... format_specifier: The format specifier in the above syntax specifies how the value is to be formatted.
🌐
ZetCode
zetcode.com › python › decimal
Python Decimal - high-precision calculations in Python with Decimal
January 29, 2024 - Neither of the types is perfect; generally, decimal types are better suited for financial and monetary calculations, while the double/float types for scientific calculations. The Decimal has a default precision of 28 places, while the float has 18 places. ... #!/usr/bin/python from decimal ...
🌐
Python
docs.python.org › 3 › library › decimal.html
decimal — Decimal fixed-point and floating-point arithmetic — Python 3.14.6 documentation
For example, Decimal((0, (1, 4, 1, 4), -3)) returns Decimal('1.414'). If value is a float, the binary floating-point value is losslessly converted to its exact decimal equivalent. This conversion can often require 53 or more digits of precision.
🌐
Berkeley
pythonnumericalmethods.studentorg.berkeley.edu › notebooks › chapter09.02-Floating-Point-Numbers.html
Floating Point Numbers — Python Numerical Methods
Instead of utilizing each bit as ... \(f\), which is the coefficient of the exponent. Almost all platforms map Python floats to the IEEE754 double precision - 64 total bits....
🌐
CodeRivers
coderivers.org › blog › python-float-precision-format
Python Float Precision Format: A Comprehensive Guide - CodeRivers
February 22, 2026 - from decimal import Decimal, getcontext # Set the precision getcontext().prec = 20 a = Decimal('1.0') b = Decimal('3.0') result = a / b print(result) In this example, the precision is set to 20 digits, which can be adjusted according to the requirements of the calculation. Simple display: If you only need to display a floating-point number with a certain number of decimal places for user consumption, string formatting (using format() or f-strings) or the round() function is usually sufficient.
🌐
Finxter
blog.finxter.com › home › learn python blog › python convert float to string
Python Convert Float to String - Be on the Right Side of Change
March 9, 2024 - For example, the expression f'{x:.3f}' converts the float variable x to a float with precision 3. ... Note that the float value 1.23456789 is rounded to 1.235 with three digits after the decimal place. To set the precision after the comma when converting a float to a string in Python, you can ...
🌐
The FinAnalytics
thefinanalytics.com › post › understanding-python-floats-operations-casting-and-best-practices
Understanding Python Floats: Operations, Casting, and Best Practices
June 1, 2025 - Under the hood, Python’s float type is a 64-bit double-precision number, providing about 15–17 decimal digits of precision. This makes floats suitable for many scientific and financial calculations that require fractional values.
🌐
The Floating-Point Guide
floating-point-gui.de › languages › python
The Floating-Point Guide - Floating-point cheat sheet for Python
Python has an arbitrary-precision decimal type named Decimal in the decimal module, which also allows to choose the rounding mode. a = Decimal('0.1') b = Decimal('0.2') c = a + b # returns a Decimal representing exactly 0.3
🌐
Mimo
mimo.org › glossary › python › float
Mimo: The coding platform you need to learn Web Development, Python, and more.
... Dividing two numbers results in a float, even if both numbers are integers. ... # Generating a float by dividing two integers third = 1 / 3 # Results in a float, approximately 0.3333 · The return value of such operations is always a float, ensuring precision even when the inputs are whole ...
🌐
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 - The code below displays the same calculation as before, only it’s displayed more neatly: ... >>> f"One third, rounded to two decimal places is: {1 / 3:.2f}" 'One third, rounded to two decimal places is: 0.33'
🌐
Medium
medium.com › @coucoucamille › float-formatting-in-python-ccb023b86417
Simple Float Formatting in Python | by Coucou Camille | Medium
June 15, 2022 - Python’s built-in format() function allows you to format float in any way you prefer. Syntax: {:.2f}.format(num) for rounding to 2 decimal places. {} marks a replacement field · : introduces a format specifier · .2 specify the precision as 2, or any other number · f to format the number as a decimal number · "{:.2f}".format(3.1415926) >>> '3.14'"{:.1f}".format(8.9998) >>> '9.0' Syntax: "{:+.2f}".format(num) for positive sign + ; and "{:-.2f}".format(num) for positive sign - .
🌐
Python Module of the Week
pymotw.com › 2 › decimal
decimal – Fixed and floating point math - Python Module of the Week
$ python decimal_context_manager.py Local precision: 2 3.14 / 3 = 1.0 Default precision: 28 3.14 / 3 = 1.046666666666666666666666667 · Contexts can be used to construct Decimal instances, applying the precision and rounding arguments to the conversion from the input type.