|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2008-09-21 19:44 UTC] lbayuk at users dot sourceforge dot net
Description:
------------
PHP printf, sprintf, and fprintf with %e scientific notation produce a 1 digit exponent for values less than 1e10. Other implementation of functions by the same name produce a minimum of 2 digits in the exponent, as the C standard requires. Although it can be argued that PHP is not bound by other standards, the following comment in main/snprintf.c function php_conv_fp() [line 545] leads one to believe this is a PHP bug:
/*
* Make sure the exponent has at least 2 digits
*/
Reproduce code:
---------------
<?php
printf("%8.2e\n", 1000000);
Expected result:
----------------
1.00e+06
Actual result:
--------------
<space>1.00e+6
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Dec 10 09:00:01 2025 UTC |
After taking a look at your patch, approximately: /* * Make sure the exponent has at least 2 digits */ + if (t_len <= 1) { + *s++ = '0'; + } while (t_len--) { I got curious, since the code you added is described by the existing comment. So I checked back through CVS and sure enough similar code was there a while ago and was removed. It was: if (t_len == 1) *s++ = '0'; So it looks like the 2-digit minimum exponent code was *removed*. Certainly we would not want to put the code back in until we determine why it came out... perhaps there was a good reason. I haven't yet located the exact file version where the change was made.