Python Forum
Formatting float number output
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Formatting float number output
#1
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.
Reply
#2
(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.
Reply
#3
(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
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  python calculate float plus float is incorrect? sirocawa 6 309 Apr-16-2024, 01:45 PM
Last Post: DeaD_EyE
  capturing multiline output for number of parameters jss 3 825 Sep-01-2023, 05:42 PM
Last Post: jss
  float("{:.2f}" return long number? korenron 2 1,042 Jul-13-2022, 05:35 AM
Last Post: korenron
  TypeError: float() argument must be a string or a number, not 'list' Anldra12 2 4,888 Jul-01-2022, 01:23 PM
Last Post: deanhystad
  formatting float like int for whole values Skaperen 8 1,760 Apr-11-2022, 01:56 PM
Last Post: deanhystad
  Search text in PDF and output its page number. atomxkai 21 8,997 Jan-21-2022, 06:20 AM
Last Post: snippsat
  Formatting to output file Mark17 2 1,326 Jan-13-2022, 09:06 PM
Last Post: BashBedlam
  Is there a better way of formatting os.uname() output? CodeWolf 6 3,675 Aug-27-2021, 11:41 PM
Last Post: CodeWolf
  Float Formatting Kristenl2784 3 1,750 Jul-30-2020, 04:49 PM
Last Post: bowlofred
  Comaparing Float Values of Dictionary Against A Float Value & Pick Matching Key firebird 2 3,397 Jul-25-2019, 11:32 PM
Last Post: scidam

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020