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

David Chambers report at bugs.python.org
Tue May 26 10:15:19 EDT 2020


New submission from David Chambers <dc at davidchambers.me>:

According to https://docs.python.org/3/library/string.html#format-specification-mini-language, “insignificant trailing zeros are removed from the significand” when 'g' is specified. I encountered a situation in which a trailing zero is not removed:

    $ python3
    Python 3.7.7 (default, Mar 10 2020, 15:43:03)
    [Clang 11.0.0 (clang-1100.0.33.17)] on darwin
    Type "help", "copyright", "credits" or "license" for more information.
    >>> '{0:.3g}'.format(1504)
    '1.5e+03'
    >>> '{0:.3g}'.format(1505)
    '1.50e+03'
    >>> '{0:.3g}'.format(1506)
    '1.51e+03'

Is this behaviour intentional? If so, why is the trailing zero in 1.50 considered significant for 1505 but insignificant for 1504?

----------
messages: 369983
nosy: davidchambers
priority: normal
severity: normal
status: open
title: str.format() handles trailing zeros inconsistently in “general” format
type: behavior

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


More information about the New-bugs-announce mailing list