"%.2f" does not return a clean float. It returns a string representing this float with two decimals.

my_list = [0.30000000000000004, 0.5, 0.20000000000000001]
my_formatted_list = [ '%.2f' % elem for elem in my_list ]

returns:

['0.30', '0.50', '0.20']

Also, don't call your variable list. This is a reserved word for list creation. Use some other name, for example my_list.

If you want to obtain [0.30, 0.5, 0.20] (or at least the floats that are the closest possible), you can try this:

my_rounded_list = [ round(elem, 2) for elem in my_list ]

returns:

[0.29999999999999999, 0.5, 0.20000000000000001]
Answer from eumiro on Stack Overflow
🌐
W3Schools
w3schools.com › python › ref_func_round.asp
Python round() Function
Python Examples Python Compiler ... Python Training ... The round() function returns a floating point number that is a rounded version of the specified number, with the specified number of decimals....
Discussions

how to limit or round a float to only two decimals without rounding up
You can try the solution here: https://stackoverflow.com/a/62435913 More on reddit.com
🌐 r/learnpython
12
5
January 26, 2024
rounding - How to round to 2 decimals with Python? - Stack Overflow
If anyone does not place the f after .2, a number like 14.426599999999999 will round to 1.4e+01. As far as Python 3.8.6 2021-06-28T21:35:14.95Z+00:00 ... @martin36, this is not an incorrect result, since 39.555 cannot be represented exactly in floating-point format, so Python will actually ... More on stackoverflow.com
🌐 stackoverflow.com
Floating point numbers to two decimal places - possible with standard lib?
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 ... More on forum.freecodecamp.org
🌐 forum.freecodecamp.org
0
August 24, 2022
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
🌐
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.
🌐
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 Python, we can use the decimal module to round floating-point numbers to a specific number of decimal places with higher precision and control compared to the built-in floating-point arithmetic.
🌐
Codecademy
codecademy.com › article › rounding-to-two-decimal-places-in-pythonn
Rounding to Two Decimal Places in Python | Codecademy
In Python, we can use the built-in round function to round floating-point numbers to a specified number of decimal places. One of the features of Python’s round() function is its implementation of “round half to even,” also known as ...
Find elsewhere
🌐
Mimo
mimo.org › glossary › python › round-function
Mimo: The coding platform you need to learn Web Development, Python, and more.
... from decimal import Decimal, ROUND_HALF_UP # Create Decimal objects instead of using floats num = Decimal('2.675') # Use the quantize() method to round to two decimal places with rounding mode ROUND_HALF_UP rounded_num = num.quantize(Decimal('0.01'), rounding=ROUND_HALF_UP) print(rounded_num) ...
🌐
DataCamp
datacamp.com › tutorial › python-round-to-two-decimal-places
How to Round to 2 Decimal Places in Python | DataCamp
August 8, 2024 - You will also find the Python Cheat Sheet for Beginners useful as a quick reference if you need a refresher on Python syntax and functions. The simplest method to round a number to two decimal places in Python is by using the built-in round() function, which is pretty straightforward.
🌐
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')
🌐
Real Python
realpython.com › python-rounding
How to Round Numbers in Python – Real Python
December 7, 2024 - Python’s built-in round() function ... To round numbers to specific decimal places, you can use the round() function with a second argument specifying the number of decimals....
🌐
freeCodeCamp
freecodecamp.org › news › how-to-round-to-2-decimal-places-in-python
How to Round to 2 Decimal Places in Python
August 22, 2022 - For rounded2, the num is rounded up to 2 decimal places. At the 2nd decimal place is 4, and the number after it is 5. Since this number is greater than or equal to 5, the number 4 is rounded up to 5. Rounding up numbers can be useful for keeping floating numbers within fixed digits.
🌐
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 - Pass input number, 2 (decimal value) as arguments to the round() function to round the input number upto the 2 decimal places. Print the rounded value of the input floating-point number upto 2 decimals.
🌐
Python Shiksha
python.shiksha › home › tips › 3 python ways to limit float up to two decimal places
3 Python ways to Limit float up to two decimal places - Python Shiksha
July 18, 2021 - Actually , the round() function takes in two arguments, first one is the number to be rounded and the second is the number of places to be rounded off to. But if no second argument is passed then the function considers it to be zero and rounds ...
🌐
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 ...
🌐
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 - To limit a float to two decimal points use the Python round() function, you simply need to pass the float as the first argument and the value 2 as the second argument.
🌐
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 - Like before when we only used %f for the full float value to be showcased, but here we are adding “%.1f” for the 1 digit to appear after the decimal and “%.2f” for the 2 digits to appear after the decimal.
🌐
PythonHow
pythonhow.com › how › limit-floats-to-two-decimal-points
Here is how to limit floats to two decimal points in Python
In this case, the float x is rounded to two decimal points, resulting in the value 3.14.Alternatively, you can use the format function to format a float as a string with a fixed number of decimal points. Here is an example of how to use format to limit a float to two decimal points: x = 3.14159265 # Format x as a string with two 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.
🌐
Finxter
blog.finxter.com › 5-best-ways-to-round-float-to-2-decimals-in-python
5 Best Ways to Round Float to 2 Decimals in Python – Be on the Right Side of Change
In the code above, the placeholder {:.2f} within the string defines the format, indicating that the float should be formatted with two decimal places. The format method then replaces the placeholder with the rounded number. The Decimal module in Python provides arithmetic with as much precision as needed.
🌐
Pandas
pandas.pydata.org › docs › reference › api › pandas.DataFrame.round.html
pandas.DataFrame.round — pandas 3.0.1 documentation
A DataFrame with the affected columns rounded to the specified number of decimal places. ... Round a numpy array to the given number of decimals. ... Round a Series to the given number of decimals. ... For values exactly halfway between rounded decimal values, pandas rounds to the nearest even value (e.g. -0.5 and 0.5 round to 0.0, 1.5 and 2.5 round to 2.0, etc.).