php.net |  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-02-12 23:15 UTC
Votes:1
Avg. Score:3.0 ± 0.0
Reproduced:0 of 0 (0.0%)
From: markamery at btinternet dot com Assigned: cmb (profile)
Status: Verified Package: Strings related
PHP Version: Irrelevant OS:
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2019-01-12 18:26 UTC] markamery at btinternet dot com
Description:
------------
At http://php.net/manual/en/function.sprintf.php, 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 https://stackoverflow.com/q/54162152/1709587 where I explore this point at length.


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2019-01-14 04:44 UTC] girgias@php.net
-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] girgias@php.net
Thanks for noticing this, you can also submit a patch to fix the documentation by using the online editor located at https://edit.php.net
 [2019-02-12 20:43 UTC] girgias@php.net
-Assigned To: +Assigned To: girgias
 [2019-02-12 23:15 UTC] girgias@php.net
-Assigned To: girgias +Assigned To: cmb
 [2019-02-12 23:15 UTC] girgias@php.net
Wrote a patch to improve the sprintf doc:
http://edit.php.net/?patchID=3291&project=PHP

@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.
 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Thu Feb 21 10:01:25 2019 UTC