Since this post might be here for a while, lets also point out python 3 syntax:

"{:.2f}".format(5)
Answer from Daren Thomas on Stack Overflow
๐ŸŒ
Finxter
blog.finxter.com โ€บ python-convert-float-to-string
Python Convert Float to String โ€“ Be on the Right Side of Change
To set the precision after the comma to two decimal places when converting a float to a string, you can use Pythonโ€™s f-string formatting functionality. For example, the expression f'{x:.2f}' converts the float variable x to a float with precision two (โ€œ2โ€) such as 1.23 or 3.14.
๐ŸŒ
freeCodeCamp
forum.freecodecamp.org โ€บ python
Floating point numbers to two decimal places - possible with standard lib? - Python - The freeCodeCamp Forum
August 24, 2022 - Iโ€™m trying to get 2 decimal places of 0s (e.g, 9.00) in the budget app project. I tried using string formatting, but the program expects a floating point number, not a string. Casting it to a float results in a single .0 because thatโ€™s how floating point numbers work in Python - that gets ...
๐ŸŒ
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 - This method is useful for generating ... in Python applications. However, modern formatting methods like f-strings and the format() function are replacing it. num = 54.45356 # Using the % operator for string formatting rounded_num = "%.2f" % num print(rounded_num) ... To format a floating-point number with two decimal places in ...
๐ŸŒ
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....
๐ŸŒ
DataCamp
datacamp.com โ€บ tutorial โ€บ python-round-to-two-decimal-places
How to Round to 2 Decimal Places in Python | DataCamp
August 8, 2024 - The % operator offers a traditional method of formatting numbers to two decimal places. The % operator allows for creating formatted strings by inserting values into placeholders. In the example below, f indicates the value as a floating-point number while .2 specifies the decimal places to ...
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
๐ŸŒ
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 - In this article, we will round off a float value in Python to the nearest two decimal places. Python provides us with multiple approaches to format numbers 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 f-string in Python is used to format a string. It can also be used to get 2 decimal places of a float value.
๐ŸŒ
Spark By {Examples}
sparkbyexamples.com โ€บ home โ€บ python โ€บ python limit floats to two decimal points
Python Limit Floats to Two Decimal Points - Spark By {Examples}
May 31, 2024 - We have explained multiple ways to limit floats to two decimal points in Python. You have learned the round() function, string formatting, f-strings, the Decimal module. I hope this article was helpful.
๐ŸŒ
Finxter
blog.finxter.com โ€บ python-string-to-float-with-2-decimals-easy-conversion-guide
Python String to Float with 2 Decimals: Easy Conversion Guide โ€“ Be on the Right Side of Change
Hereโ€™s the syntax for a float with two decimal places: your_float = 7.326 formatted_float = f"{your_float:.2f}" print(formatted_float) # Output: 7.33 ยท F-strings are a powerful and friendly way to handle precision and formatting directly within your string literals. In this section, youโ€™ll see how to translate string representations of numbers in Python ...
๐ŸŒ
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 format a float for neat display within a Python f-string, you can use a format specifier. In its most basic form, this allows you to define the precision, or number of decimal places, the float will be displayed with.
๐ŸŒ
Quora
quora.com โ€บ In-Python-how-could-I-convert-a-float-with-one-decimal-place-into-a-float-with-two-decimal-places-for-example-24-3-to-24-30
In Python, how could I convert a float with one decimal place into a float with two decimal places (for example, 24.3 to 24.30)? - Quora
Answer (1 of 4): You don't convert floats like that. You really mean how to PRINT numbers in different formats. In current Python: x = 24.3 (in the computer, x has at least 10 decimal places) print(f"[x:4.2f]โ€) !!!!! This keyboard does not have the braces key โ€ฆ. use braces instead of [ ] !!!...
๐ŸŒ
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.
๐ŸŒ
ItSolutionstuff
itsolutionstuff.com โ€บ post โ€บ python-convert-string-to-float-with-2-decimal-places-exampleexample.html
Python Convert String to Float with 2 Decimal Places Example - ItSolutionstuff.com
October 30, 2023 - This extensive guide will teach you python convert string to float with 2 decimal places. We will look at an example of python string to 2 decimal places. we will help you to give an example of python string to float 2 decimal.
๐ŸŒ
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 assign it the value 3.1415926 (a floating-point number). x = 3.1415926 # Define a variable 'y' and assign it the value 12.9999 (a floating-point number).
๐ŸŒ
Reddit
reddit.com โ€บ r/learnpython โ€บ convert float to string without losing precision.
r/learnpython on Reddit: Convert float to string without losing precision.
January 6, 2021 -

I am looking to manipulate a data frame of floats which all need 6 decimal points after manipulation.

I am looking to add brackets and () around the floats based on conditionals which is why I need to convert to strings. I then can concat the two strings together

However when I convert to str, it reduces the number of decimals to 2.

For example

-35.920000 Original Dataframe

Converted to str

-35.92 After conversion

If I convert the string back to a float, it does not retain the 6 decimals from the original df.

My understanding is both values are stored the same and they both are logically = when checked in the notebook , but for management reasons I am trying to see if there is a way to coerce the string method the take a literal copy of the float, rather than reducing it down.

Sorry for the formatting, I am on mobile .

Thanks