[docs] [issue13433] String format documentation contains error regarding %g

Terry J. Reedy report at bugs.python.org
Sat Nov 26 01:08:48 CET 2011


Terry J. Reedy <tjreedy at udel.edu> added the comment:

I find the doc for g/G less than clear.

1. (main entry) "Uses lowercase exponential format if exponent is less than -4 or not less than precision, decimal format otherwise."

'not less' means 'equal or greater', which to me is clearer. Even better and clearer to me would be "Uses decimal format if -4 <= exponent < precision, exponential format otherwise."


2. (note 4) "The precision determines the number of significant digits before and after the decimal point and defaults to 6."

>>> 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 <report at bugs.python.org>
<http://bugs.python.org/issue13433>
_______________________________________


More information about the docs mailing list