21 Jan
2020
21 Jan
'20
1:16 p.m.
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