Converting 5.223701009526849e-05 to 5e-05
Ben Finney
ben+python at benfinney.id.au
Sun May 3 04:48:36 EDT 2015
Ben Finney <ben+python at benfinney.id.au> writes:
> Assuming we're talking about a ‘float’ value::
>
> >>> foo = 5.223701009526849e-05
> >>> "{foo:5.1}".format(foo=foo)
> '5e-05'
That's not as clear as it could be. Better is to be explicit about
choosing “exponential” format::
>>> foo = 5.223701009526849e-05
>>> "{foo:5.0e}".format(foo=foo)
'5e-05'
--
\ “Science embraces facts and debates opinion; religion embraces |
`\ opinion and debates the facts.” —Tom Heehler, _The Well-Spoken |
_o__) Thesaurus_ |
Ben Finney
More information about the Python-list
mailing list