Terry J. Reedy added the comment:

"The precision is a decimal number indicating how many digits should be 
displayed ... before and after the decimal point for a floating point value 
formatted with 'g' or 'G'. It seems that str, repr, and '' are using precision 
16, and the doc should be changed to match.

>>>str(.314159265358979323846264338327950288419)
'0.3141592653589793' # 16, not counting 0.

>>> '{}'.format(3.14159265358979323846264338327950288419)
'3.141592653589793'
>>> '{:.16g}'.format(3.14159265358979323846264338327950288419)
'3.141592653589793'
>>> str(3.14159265358979323846264338327950288419)
'3.141592653589793'  # 16

But I discovered this 'anomaly' (bug?)
>>> str(31.4159265358979323846264338327950288419)
'31.41592653589793'
>>> str(33.14159265358979323846264338327950288419)
'33.1415926535898'  # precision 15
I expected this last to be
'33.14159265358979'
as 32... rounds down, not up.

repr and '{}'.format act the same.

----------
nosy: +terry.reedy
stage:  -> needs patch
type:  -> behavior
versions: +Python 3.4, Python 3.5 -Python 3.3

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue22546>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to