[issue13433] String format documentation contains error regarding %g
New submission from Christian Iversen
"%g" % 2.1234567 '2.12346' "%f" % 2.1234567 '2.123457' "%e" % 2.1234567 '2.123457e+00'
But something much more insidious is wrong, because even when explicitly told how many digits to have, %g is one off:
"%.6g" % 2.1234567 '2.12346' "%.6f" % 2.1234567 '2.123457' "%.6e" % 2.1234567 '2.123457e+00'
This can't be right?
----------
assignee: docs@python
components: Documentation
messages: 147940
nosy: Christian.Iversen, docs@python
priority: normal
severity: normal
status: open
title: String format documentation contains error regarding %g
type: behavior
versions: Python 2.6, Python 2.7
_______________________________________
Python tracker
Mark Dickinson
Christian Iversen
Mark Dickinson
Maybe a note describing that %g is different from the others in this regard?
-1 from me; I don't really see that that would improve the documentation. Maybe that's just me, but I expect reference documentation to be clean, and uncluttered with too many warnings. All the necessary information is already there, and adding extra notes like this just increases the total number of words to be read without adding new information.
In a tutorial, that would be different ... :-)
Leaving this open---others may have different takes on this.
----------
_______________________________________
Python tracker
Changes by Eric V. Smith
Changes by Mark Dickinson
Éric Araujo
Christian Iversen
Terry J. Reedy
format(.001, 'g') '0.001'
I only count 4, not 6. Whoops, that is sort of documented, but in a really backwards way, by saying what the alternate form is. "The alternate form ... trailing zeroes are not removed as they would otherwise be."
format(.001, '.3g') '0.001'
Now I count 4, not 3. 3. (several notes) 'The alternate form'? I initially though this meant one of the two forms for g/G but then saw it used for other formats with just one form. It took too much searching to find the entry for '#', which I had never noticed before. Please expand to "The alternate '#' form" or add "(Alternate forms are selected by the '#' flag.)" after "Notes:". I agree with C.I. that we could give some subtle emphasis that g/G treat precision differently. But the difference is more than just including the minimum 1 char before the decimal point in the precision.
format(.001, 'f') '0.001000'
----------
nosy: +terry.reedy
_______________________________________
Python tracker
Christian Iversen
Change by Irit Katriel
Mark Dickinson
participants (6)
-
Christian Iversen
-
Eric V. Smith
-
Irit Katriel
-
Mark Dickinson
-
Terry J. Reedy
-
Éric Araujo