Python Forum

Full Version: Formatting float number output
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Is there a way to globally set the output of printed floats to 2 decimal places?
I would rather not have to use..print('{:010.4f}'.format(x)) for each print statement.
(May-04-2023, 01:39 PM)barryjo Wrote: [ -> ]I would rather not have to use..print('{:010.4f}'.format(x)) for each print statement.
This doesn't output the float to 2 decimal spaces
>>> from math import pi
>>> x = pi
>>> print('{:010.4f}'.format(x))
00003.1416
so what do you want exactly?
(May-04-2023, 01:39 PM)barryjo Wrote: [ -> ]for each print statement.
Do you have that many print statements in your code? You could perhaps bury them into functions.
(May-04-2023, 01:54 PM)Gribouillis Wrote: [ -> ]
(May-04-2023, 01:39 PM)barryjo Wrote: [ -> ]I would rather not have to use..print('{:010.4f}'.format(x)) for each print statement.
This doesn't output the float to 2 decimal spaces
>>> from math import pi
>>> x = pi
>>> print('{:010.4f}'.format(x))
00003.1416
so what do you want exactly?
(May-04-2023, 01:39 PM)barryjo Wrote: [ -> ]for each print statement.
Do you have that many print statements in your code? You could perhaps bury them into functions.

I think your suggestion to bury the print in a function might be the best. Thanks