As no one has added it, it should be noted that going forward from Python 2.6+ the recommended way to do string formating is with format, to get ready for Python 3+.

print ["{0:0.2f}".format(i) for i in a]

The new string formating syntax is not hard to use, and yet is quite powerfull.

I though that may be pprint could have something, but I haven't found anything.

Answer from Esteban Küber on Stack Overflow
🌐
W3Schools
w3schools.com › python › python_string_formatting.asp
Python String Formatting
A modifier is included by adding a colon : followed by a legal formatting type, like .2f which means fixed point number with 2 decimals: ... You can perform Python operations inside the placeholders. ... price = 59 tax = 0.25 txt = f"The price is {price + (price * tax)} dollars" print(txt) Try it Yourself »
Discussions

General way to print floats without the .0 part
I’m building SVG code using data interpolation (f-strings and .format), and I have elements (the size of the graph for one) that are internally floats but which are usually integers. But when printing floats, the .0 part is always included. Is there a standard str-interpolation idiom that ... More on discuss.python.org
🌐 discuss.python.org
0
May 19, 2024
Trying to format a list of floats with f-strings
You can't format an entire list all at once. You have to format each number individually, and then unpack that to print it: print("Roots:", *(f"{x:.3f}" for x in roots)) or you could use join to combine the formatted numbers: print("Roots:", ' '.join(f"{x:.3f}" for x in roots)) More on reddit.com
🌐 r/learnpython
6
2
July 23, 2018
How can I control the number of decimals when printing a float?
value = 123.456789 for p in range(1, 11): print(f'{value:.{p}f}') This prints: 123.5 123.46 123.457 123.4568 123.45679 123.456789 123.4567890 123.45678900 123.456789000 123.4567890000 More on reddit.com
🌐 r/learnpython
8
4
August 5, 2021
Math with Significant Figures
Congrats on getting to a point where you're happy to share code, great to see! In terms of the utility of this, I might be missing something. My background is PhD in Physics + Software Engineering, so my experience here is from my physics courses. That being said, when doing calculations, you want to always calculate your sums with the full precision. Rounding to N significant figures should only happen right at the end when exporting the numbers into your paper/article/experimental write/etc. So my own library, ChainConsumer , when asked to output final LaTeX tables, will determine significant figures and output... but only a very final step. I'm curious why you aren't simply formatting your final results, and instead seem to be introducing compounding rounding errors. In terms of the code itself, I'd encourage you to check out tools like black that you can use to format your code automatically. You can even set things up so the editors like VSCode run black when you save the file, or a pre-commit that runs black prior to your work being committed. More on reddit.com
🌐 r/Python
53
152
October 17, 2022
🌐
Python documentation
docs.python.org › 3 › tutorial › inputoutput.html
7. Input and Output — Python 3.14.3 documentation
An optional format specifier can follow the expression. This allows greater control over how the value is formatted. The following example rounds pi to three places after the decimal: >>> import math >>> print(f'The value of pi is approximately {math.pi:.3f}.') The value of pi is approximately 3.142.
🌐
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. ... Syntax: "{:+.2f}".format(num) for positive sign + ; and "{:-.2f}".format(num) for positive ...
🌐
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 - >>> value = 13579+0.0245j >>> print( ... # Write your solution here ... ) The real part is 1.36E+04 and the imaginary part 2.45E-02. See if you can work out the required format specifiers. Remember, you’re aiming for an uppercase E so you may need to read the documentation. You’ll find possible solutions in the downloadable materials that accompany this tutorial. ... The Python float type limits you to 64 bits of storage for storing your numbers.
🌐
TutorialsPoint
tutorialspoint.com › how-to-format-a-floating-number-to-fixed-width-in-python
How to format a floating number to fixed width in Python?
November 13, 2024 - We can format a floating-point number to a fixed width by using Python's f-strings, in below code '.2f' specifies that the number should formatted as a floating-point number with 2 decimal places. number = 123.4568 formatted = f"{number:10.2f}" print(formatted)
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-output-formatting
Python - Output Formatting - GeeksforGeeks
Python · # Advanced formatting with positional and named arguments # Mixing positional and named arguments template = "Number one portal is {0}, {1} and {other}." print(template.format("Geeks", "For", other="Geeks")) # Format integers and floats with specified width and precision print("Geeks :{0:2d}, Portal :{1:8.2f}".format(12, 0.5534)) # Demonstrate order swapping and formatting precision print("Second argument: {1:3d}, first one: {0:8.2f}".format(47.42, 11)) # Using named arguments for clarity in complex formats print("Geeks: {a:5d}, Portal: {p:8.2f}".format(a=453, p=59.058)) Output ·
Published   July 11, 2025
Find elsewhere
🌐
Mooc
programming-24.mooc.fi › part-4 › 5-print-statement-formatting
Print statement formatting - Python Programming MOOC 2024
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. a floating point number. Here's another example, where we specify the amount of whitespace reserved for the variable in the printout.
🌐
Python.org
discuss.python.org › python help
General way to print floats without the .0 part - Python Help - Discussions on Python.org
May 19, 2024 - I’m building SVG code using data interpolation (f-strings and .format), and I have elements (the size of the graph for one) that are internally floats but which are usually integers. But when printing floats, the .0 part is always included. Is there a standard str-interpolation idiom that ...
🌐
The Teclado Blog
blog.teclado.com › python-formatting-numbers-for-printing
Formatting Numbers for Printing in Python
March 23, 2023 - For large numbers we often write a separator character (usually a comma, space, or period) to make it easier to read. We can specify this in Python using a comma or underscore character after the colon. x = 1000000 print(f"{x:,}") # 1,000,000 print(f"{x:_}") # 1_000_000 · This also works with floats, and the precision formatting, with the comma coming first:
🌐
Python Reference
python-reference.readthedocs.io › en › latest › docs › functions › format.html
format — Python Reference (The Right Way) 0.1 documentation
>>> #This example illustrates the use of [type] option on integers >>> format(2, 'b') '10' >>> format(2, 'b') '10' >>> format(2, 'c') '\x02' >>> format(2, 'd') '2' >>> format(100, 'o') '144' >>> format(100, 'x') '64' >>> format(100, 'n') '100' >>> format(100) '100' >>> #This example illustrates the use of [type] option on floats >>> format(3.13592, 'e') '3.135920e+00' >>> format(3.13592, 'E') '3.135920E+00' >>> format(3.13592, 'f') '3.135920' >>> format(3.13592, 'g') '3.13592' >>> format(3.13592, '.2g') '3.1' >>> format(3.13592, '%') '313.592000%' >>> format(3.13592, '.2%') '313.59%' >>> format(3.13592, 'n') '3.13592'
🌐
freeCodeCamp
freecodecamp.org › news › 2f-in-python-what-does-it-mean
%.2f in Python – What does it Mean?
June 22, 2022 - You can play around with the code to see what happens as you change the number in the formatter. Another formatting method we can use with floating point numbers in Python is the %d formatter.
🌐
mkaz.blog
mkaz.blog › working-with-python › string-formatting
Python String Formatting: Complete Guide
Usage: print(f"{NUMBER:FORMAT}") ... Minimum field width · ,: Use comma as thousands separator · precision: Digits after decimal point · type: f (float), d (decimal), e (scientific), % (percentage) F-strings support more than just variable substitution - you can include ...
🌐
DataCamp
campus.datacamp.com › courses › data-types-in-python › numeric-data-types-booleans-and-sets
Printing floats | Python
For example, if we wanted to format a variable in an f string as a float, we can use the f format specifier, such as: print(f"{some_variable:f}").
🌐
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 ...
🌐
Finxter
blog.finxter.com › home › learn python blog › 5 best ways to format and print lists of floats in python
5 Best Ways to Format and Print Lists of Floats in Python - Be on the Right Side of Change
February 24, 2024 - float_list = [3.14159265, 1.6180339, 2.7182818] formatted_list = ['{:.2f}'.format(i) for i in float_list] print(formatted_list) ... This approach uses a list comprehension to create a new list of strings, with each float formatted to two decimal places. The .2f inside the curly braces tells the format() function to convert the floating-point number to a string with 2 decimal places. The "%.2f" operator is an older formatting option in Python, known as printf-style String Formatting.
🌐
AskPython
askpython.com › home › understanding the print format %.3f in python
Understanding the Print Format %.3f in Python - AskPython
March 30, 2023 - In Python, the “%.3f” format specifier is a method for formatting floating-point numbers to display only three decimal places. This is achieved using the ‘%’ operator along with the ‘%.nf’ format specifier, where ‘n’ determines ...
🌐
LabEx
labex.io › tutorials › python-how-to-handle-typeerror-with-float-in-python-format-417792
How to handle TypeError with float in Python format | LabEx
One of the most convenient ways to handle type errors with floats in Python formatting is to use f-strings (formatted string literals), introduced in Python 3.6. F-strings automatically handle type conversions, making it easy to include float ...