|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #69578 sprintf missing g-format
Submitted: 2015-05-06 00:04 UTC Modified: 2015-05-06 05:05 UTC
From: dlai7 at bigbiz dot com Assigned:
Status: Closed Package: Strings related
PHP Version: 5.4.40 OS: Linux
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
Solve the problem:
28 - 25 = ?
Subscribe to this entry?

 [2015-05-06 00:04 UTC] dlai7 at bigbiz dot com
Running the test script below tries to format a number using
%d %e $f and %g formats in sprintf

However the output is blank for %g format

It appears %g isn't supported

15.5 d value is 15
15.5 e value is 1.55000e+1
15.5 f value is 15.500000
15.5 g value is 
0.5 d value is 0
0.5 e value is 5.00000e-1
0.5 f value is 0.500000
0.5 g value is 
155 d value is 155
155 e value is 1.55000e+2
155 f value is 155.000000
155 g value is 

Test script:
        echo "15.5 d value is ",sprintf('%d',15.5),"\n";
  	echo "15.5 e value is ",sprintf('%e',15.5),"\n";
  	echo "15.5 f value is ",sprintf('%f',15.5),"\n";
  	echo "15.5 g value is ",sprintf('%g',15.5),"\n";
  	echo "0.5 d value is ",sprintf('%d',0.5),"\n";
  	echo "0.5 e value is ",sprintf('%e',0.5),"\n";
  	echo "0.5 f value is ",sprintf('%f',0.5),"\n";
  	echo "0.5 g value is ",sprintf('%g',0.5),"\n";
  	echo "155 d value is ",sprintf('%d',155),"\n";
  	echo "155 e value is ",sprintf('%e',155),"\n";
  	echo "155 f value is ",sprintf('%f',155),"\n";
  	echo "155 g value is ",sprintf('%g',155),"\n";

Expected result:
Expecting %g format to output similar to the C sprintf function


15.5 g value is 15.5
0.5 g value is 0.5
155 g value is 155


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2015-05-06 01:40 UTC]
-Status: Open +Status: Feedback -Package: Unknown/Other Function +Package: Strings related
 [2015-05-06 01:40 UTC]
Seems to be working fine.

Definitely 5.4.40? Which Linux? Can you try other versions of PHP?
 [2015-05-06 05:05 UTC] dlai7 at bigbiz dot com
-Status: Feedback +Status: Closed
 [2015-05-06 05:05 UTC] dlai7 at bigbiz dot com
Its 5.1.6, sorry.  I wasnt able to pick that one.
PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Sun Sep 24 10:01:24 2023 UTC