php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #40482 Sprintf format specifier "e" output modification
Submitted: 2007-02-14 12:44 UTC Modified: 2007-03-23 17:07 UTC
From: kore@php.net Assigned:
Status: Closed Package: Documentation problem
PHP Version: 5.2.1 OS: Linux 2.6.20
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: kore@php.net
New email:
PHP Version: OS:

 

 [2007-02-14 12:44 UTC] kore@php.net
Description:
------------
There is no real category for sprintf() or string functions issues, I hope the selected one fits the issue.

Between PHP 5.2.1 RC1 and PHP 5.2.1 the resulting output with the format specifier "e" changed. All PHP version prior to 5.2.1 tested by me have the same result as PHP 5.2.0.

Even the tests were changed to reflect this new behavior: http://cvs.php.net/viewvc.cgi/php-src/ext/standard/tests/strings/sprintf_f_2.phpt?r1=1.1.2.3&r2=1.1.2.4

Reproduce code:
---------------
$ php -r 'var_dump( sprintf( "%.3e", 0.0000234 ) );'

Expected result:
----------------
string(7) "2.34e-5"

Actual result:
--------------
string(8) "2.340e-5"

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-02-14 12:49 UTC] tony2001@php.net
That was actually a bugfix.
sprintf( "%.3e", 0.0000234 );
          ^^^^ it's "3 digits after the floating point"

string(8) "2.340e-5"
             ^^^ 3 digits, not 2. 
 [2007-02-15 10:48 UTC] kore@php.net
You could see the the number as the precision of the output number. You normally won't ever get more then one digit in front of the decimal point with scientific notation. Even PHP 5.2.1 acts like this:

# php -r 'var_dump( sprintf( "%2.3e", 5555555555 ) );'
string(8) "5.556e+9"

If you still do not want to change the behavior back to the old one, the new behavior should be documented:

http://de3.php.net/manual/en/function.sprintf.php Example #2308 still shows the old behavior. In this case feel free to change the bugs category to a documentation bug.
 [2007-03-23 17:07 UTC] vrana@php.net
This bug has been fixed in the documentation's XML sources. Since the
online and downloadable versions of the documentation need some time
to get updated, we would like to ask you to be a bit patient.

Thank you for the report, and for helping us make our documentation better.

"The precision specifier stands for the number of digits after the decimal point since PHP 5.2.1. In earlier versions, it was taken as number of significant digits (one less)."

Example fixed too.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Thu Jul 17 14:04:04 2025 UTC