Python Forum

Full Version: how to get non-exponential format
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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'.
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'