Python Forum
how to get non-exponential format
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
how to get non-exponential format
#1
how can i get a non-exponential format result for a floating point value. that would be a string where 'e' not in result. like '18014398509481984.0' instead of '1.8014398509481984e+16' (that i get with str(2.0**54)).

edit:

and '0.00000000000000005551115123125783' instead of '5.551115123125783e-17'.
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply
#2
You can use either format or f-strings and the "f"ixed point specifier.

>>> format(2.0**54, "f")
'18014398509481984.000000'
>>> f"{2.0**54:f}"
'18014398509481984.000000'
Default is 6 digits of decimal precision. If you need more you have to specify.

>>> format(2.0**-54, ".32f")
'0.00000000000000005551115123125783'
>>> f"{2.0**-54:.32f}"
'0.00000000000000005551115123125783'
Skaperen likes this post
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  understanding exponential and bitwise operators srm 1 2,043 Jun-15-2019, 11:14 AM
Last Post: ThomasL
  Dealing with Exponential data parthi1705 11 9,756 May-30-2019, 10:16 AM
Last Post: buran

Forum Jump:

User Panel Messages

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