Formatting float number output - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Formatting float number output (/thread-39913.html) |
Formatting float number output - barryjo - May-04-2023 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. RE: Formatting float number output - Gribouillis - May-04-2023 (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.1416so 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. RE: Formatting float number output - barryjo - May-04-2023 (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 I think your suggestion to bury the print in a function might be the best. Thanks |