Ben Finney <ben+pyt...@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 -- https://mail.python.org/mailman/listinfo/python-list