|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #77451 %g format for printf & sprintf is misdocumented
Submitted: 2019-01-12 18:26 UTC Modified: 2019-03-24 17:46 UTC
Avg. Score:3.0 ± 0.0
Reproduced:0 of 0 (0.0%)
From: markamery at btinternet dot com Assigned: girgias (profile)
Status: Closed Package: Strings related
PHP Version: Irrelevant OS:
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: markamery at btinternet dot com
New email:
PHP Version: OS:


 [2019-01-12 18:26 UTC] markamery at btinternet dot com
At, the %g specifier is documented as follows:

    shorter of %e and %f.

This isn't true. %g often uses scientific notation even though it'd be shorter not to, and what's more, its output may differ from BOTH %e and %f, since it strips trailing zeros and %f and %e don't.

See where I explore this point at length.


sprintf_related_functions_improvement (last revision 2019-03-20 17:50 UTC by

Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2019-01-14 04:44 UTC]
-Summary: %g specifier to printf is misdocumented +Summary: %g format for printf & sprintf is misdocumented -Status: Open +Status: Verified -Package: Documentation problem +Package: Strings related -Operating System: N/A +Operating System:
 [2019-01-14 04:44 UTC]
Thanks for noticing this, you can also submit a patch to fix the documentation by using the online editor located at
 [2019-02-12 20:43 UTC]
-Assigned To: +Assigned To: girgias
 [2019-02-12 23:15 UTC]
-Assigned To: girgias +Assigned To: cmb
 [2019-02-12 23:15 UTC]
Wrote a patch to improve the sprintf doc:

@cmb I was thinking to maybe move the examples out of the format parameter
and then move the format parameter XML into an entity and include this entity in all the other related functions (such as printf or fscanf for example).

Oh also I couldn't try it out as I haven't managed to download the Doc Block Rendering system onto my Linux Sub System so not totally sure how this patch looks like.
 [2019-02-26 17:33 UTC]
Updated the patch [1] to move the format parameter into an XML Snippet and added it to all relevant functions.
It validates and the doc looks good to me.

Can you have a look and/or merge it @cmb?

 [2019-03-03 14:35 UTC]
-Assigned To: cmb +Assigned To:
 [2019-03-20 17:50 UTC]
The following patch has been added/updated:

Patch Name: sprintf_related_functions_improvement
Revision:   1553104231
 [2019-03-20 17:54 UTC]
-Assigned To: +Assigned To: girgias
 [2019-03-24 16:30 UTC]
Automatic comment from SVN on behalf of girgias
Log: Improve sprintf documentation and related functions (such as printf)
Fix Doc Bug #77451
Integrate Note 111201 into doc
 [2019-03-24 17:46 UTC]
-Status: Verified +Status: Closed
PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Wed May 31 15:03:37 2023 UTC