PHP Bugs  
php.net | support | documentation | report a bug | advanced search | search howto | statistics | login

go to bug id or search bugs for  

Bug #29286 printf/sprintf floating point output change
Submitted:20 Jul 2004 8:35pm UTC Modified: 2 Aug 2004 11:39am UTC
From:michael at fishnet dot us Assigned to:
Status:Closed Category:Output Control
Version:4.3.8 OS:
View/Vote Developer Edit Submission

[20 Jul 2004 8:35pm UTC] michael at fishnet dot us
Description:
------------
The formatting of printf and sprint "%f" changed from 4.3.6 to 4.3.8. 
The change appears to have actually been released in 4.3.7, perhaps
indicated by the Changelog line "Fixed problems with *printf() functions
and '%f' formatting. (Marcus)".

Where php has for years taken the format "%4.3f" as 4 places to the left
of the decimal and 3 to the right of the decimal, it now reads it as
"total width of 4 places, including the decimal point and 3 places to
the right".  Running the code sample provided between 4.3.6 and 4.3.8
will illustrate the problem.

We use php to generate fixed width column files for an old database
import system; we found to our surprise this morning that the nightly
run did not work.

The change broke significant operational code that has been in place for
years. Warnings should have been blazened in red letters across the
release that existing code could well break.  Burying this in a cryptic
one liner in the Changelog shows little forethought or consideration for
those whose code suddenly will not work correctly, with no real warning
at all.

This probably will not be accepted as a bug.  It seems to be an
alignment of php with other language formatting systems, at least perl
and C, and I understand that.  I don't disagree with the philosophy of
the change, but I strongly disagree with the way it was done.  Though
arguably with less impact, the number format change is comparable to the
register_globals change.  Putting the change into a security release
worsened the impact, as one then has a choice to either stay with the
security problems or find a fix unknown quantities of code.  When a
foundational behavior of php is being changed in the future, please
document it profusely.

Thank you.

Reproduce code:
---------------
<?php
print "12345678901234567890123456789\n";
printf("%5.2f  %8.2f\n",3.4,89);
?>

Compare the output between 4.3.8 and 4.3.6.

Expected result:
----------------
4.3.6 output:

12345678901234567890123456789
    3.40        89.00

Actual result:
--------------
4.3.8 output:

12345678901234567890123456789
 3.40     89.00

[26 Jul 2004 4:02pm UTC] sven dot siwek at cvk dot de
My English is rather bad, please be leninent with me. 

If have following strange behaviour: 

Content-type: text/html^M
X-Powered-By: PHP/4.3.8^M
^M
 0000000000.00
 0000023.20

Please use cut and paste and see for yourself:

<?

$sfp=" %010.2f \n";

$schr=sprintf($sfp,'0.00');
$schr1=sprintf($sfp,'23.20');

echo $schr;
echo $schr1;

?>

It would be very nice to fix that as soon as possible.
Thank you
[2 Aug 2004 11:39am UTC] derick@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.

This is already fixed in CVS.
[9 Aug 2004 5:23pm UTC] mitsu at ministryofthought dot com
I completely agree. I upgraded to 4.3.8 as part of a security patch and
my code started to silently break, causing major problems for my client.
Very, very bad that this was not a big warning to PHP developers --- and
it should be posted prominently on the home page.
[9 Aug 2004 5:26pm UTC] mitsu at ministryofthought dot com
Okay, I see this has been fixed, I posted the above before seeing the
last comment on this bug.
[16 Aug 2004 11:35am UTC] markvds at elegia dot nl
It's still not clear to me what has been fixed. Has the old behaviour
been restored, or has only the bug from sven [26 jul] been fixed?

RSS feed | show source 

PHP Copyright © 2001-2009 The PHP Group
All rights reserved.
Last updated: Sat Nov 21 10:30:49 2009 UTC