[issue40780] str.format() handles trailing zeros inconsistently in “general” format

Eric V. Smith report at bugs.python.org
Tue May 26 12:12:53 EDT 2020


Eric V. Smith <eric at trueblade.com> added the comment:

For completeness, here's the output using just format, which I prefer over str.format because there's less going on: it removes all of the str.format machinery and basically directly calls obj.__format__.

>>> format(1504, '.3g')
'1.5e+03'
>>> format(1505, '.3g')
'1.50e+03'
>>> format(1506, '.3g')
'1.51e+03'

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue40780>
_______________________________________


More information about the Python-bugs-list mailing list