php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #36392 wrong number of decimal digits with %e specifier in sprintf
Submitted: 2006-02-14 19:15 UTC Modified: 2006-12-22 15:30 UTC
From: tomas_matousek at hotmail dot com Assigned:
Status: Closed Package: Strings related
PHP Version: 5.1.3RC3, 4.4.2 OS: *
Private report: No CVE-ID: None
 [2006-02-14 19:15 UTC] tomas_matousek at hotmail dot com
Description:
------------
Format specifier %e (scientific number) in sprintf() function gives results with wrong number of decimal digits and in one particular case it gives a mess.

Reproduce code:
---------------
echo sprintf("%e\n", 1.123456789);
echo sprintf("%.10e\n", 1.123456789);
echo sprintf("%.0e\n", 1.123456789);   // this gives a mess
echo sprintf("%.1e\n", 1.123456789);
echo sprintf("%5.1e\n", 1.123456789);

Expected result:
----------------
1.123457e+0
1.1234567890e+0
1e+0
1.1e+0
1.1e+0

Actual result:
--------------
1.12346e+0
1.123456789e+0
.0e+0123456789     
1.e+0
1.e+0


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-04-11 11:16 UTC] sniper@php.net
Marcus, this is your doing. :)
 [2006-12-22 15:30 UTC] iliaa@php.net
This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 18 19:01:30 2024 UTC