Am 03.05.2015 um 10:48 schrieb Ben Finney: > 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' >
Or even better the "general" format, which also works for 0.9999: >>> "{foo:.1g}".format(foo=5.223701009526849e-5) '5e-05' >>> "{foo:.1g}".format(foo=0.9999) '1' I guess all roads lead to Rome... -- https://mail.python.org/mailman/listinfo/python-list