On 1/21/2020 2:02 PM, Serhiy Storchaka wrote:
21.01.20 12:37, Eric V. Smith пише:
Yes (I wrote a lot of that), but '.17g' doesn't mean to always show 17 digits. See https://github.com/python/cpython/blob/master/Python/pystrtod.c#L825 where the repr (which is format_code =='r') is translated to format_code = 'g' and precision = 17.

But I was wrong about them being equivalent: 'g' will drop the trailing '.0' if it exists, and repr() will not (via flags = Py_DTSF_ADD_DOT_0).

This is not the only difference between '.17g' and repr().

>>> '%.17g' % 1.23456789
'1.2345678899999999'
>>> format(1.23456789, '.17g')
'1.2345678899999999'
>>> repr(1.23456789)
'1.23456789'

Huh. That's interesting. Thanks!

Eric
_______________________________________________
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-le...@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at 
https://mail.python.org/archives/list/python-dev@python.org/message/BJKU6GO65UOGCHQN2BCDTFH3XWXIYRD7/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to