Bug #69578 [Opn->Fbk]: sprintf missing g-format

From: Date: Wed, 06 May 2015 01:40:47 +0000
Subject: Bug #69578 [Opn->Fbk]: sprintf missing g-format
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-192506@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=69578&edit=1

 ID:                 69578
 Updated by:         requinix@php.net
 Reported by:        dlai7 at bigbiz dot com
 Summary:            sprintf missing g-format
-Status:             Open
+Status:             Feedback
 Type:               Bug
-Package:            Unknown/Other Function
+Package:            Strings related
 Operating System:   Linux
 PHP Version:        5.4.40
 Block user comment: N
 Private report:     N

 New Comment:

Seems to be working fine. http://3v4l.org/CO3tj

Definitely 5.4.40? Which Linux? Can you try other versions of PHP?


Previous Comments:
------------------------------------------------------------------------
[2015-05-06 00:04:35] dlai7 at bigbiz dot com

Description:
------------
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

Output:
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:
---------------
<?php
        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

example:

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




------------------------------------------------------------------------



--
Edit this bug report at https://bugs.php.net/bug.php?id=69578&edit=1


Thread (3 messages)

« previous php.bugs (#192506) next »