Bug #47304 [Com]: typecast of numeric string to float produces strange result

From: Date: Mon, 12 Jul 2010 10:43:16 +0000
Subject: Bug #47304 [Com]: typecast of numeric string to float produces strange result
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-152283@lists.php.net to get a copy of this message
Edit report at http://bugs.php.net/bug.php?id=47304&edit=1

 ID:               47304
 Comment by:       ola dot andersson at liko dot se
 Reported by:      lennartvdd at mailordersolutions dot nl
 Summary:          typecast of numeric string to float produces strange
                   result
 Status:           Feedback
 Type:             Bug
 Package:          Scripting Engine problem
 Operating System: win32 only
 PHP Version:      5.2.9
 Assigned To:      pajoye

 New Comment:

The same error occurred for me. The installation is PHP 5.2.13 installed
on IIS7/Win server 2008.

Writing a script as suggested (see below) produces incorrect output for
the echo function. The error is however intermittent. 

When refreshing the browser and rerunning the script several times
(perhaps 20-40 times) the correct numbers are sometimes displayed and
sometimes the incorrect.

Script used for testing:

for ($i=0; $i<400; $i++)
{
echo $i."-";
printf("%f\n",$i);
}


Previous Comments:
------------------------------------------------------------------------
[2010-06-15 03:49:17] xiaobo dot bob at gmail dot com

I have a win32 program writing in delphi using the component php4delphi
that can reproduce this problem. if someone need it, i can email it to
you.

or if some one can help me to compile php under vc6 with the .dsp (I can
compile 5.3.2 using nmake of vc++9, with the step-by-step direction of
the manual, but failed to compile using .dsp project). i have tried to
use the windbg.exe with the downloaded debug pack to trace into the
code, it seems the problem happens in the function php_conv_fp in
snprintf.c, but as the local variables always "memory access error", i
can't make any progress.

------------------------------------------------------------------------
[2010-06-14 14:29:27] xiaobo dot bob at gmail dot com

i tried set precision to 5/14/20, and keep the serialize_precision =
100.

"echo number_format(1900.0,2)" is always wrong.

here is my code:

echo
ini_get("precision")."/".ini_get("serialize_precision")."<br>";
echo number_format(1900.0,2)."-------\n";

------------------------------------------------------------------------
[2010-06-14 12:54:30] xiaobo dot bob at gmail dot com

wrong result for the following number is like:
17 - 16.:00
19 - 18.:00
29 - 28.:00
39 - 38.:00
170 - 16:.00
190 - 18:.00
290 - 28:.00
390 - 38:.00
1700 - 1,6:0.00
1900 - 1,8:0.00

------------------------------------------------------------------------
[2010-06-14 12:53:17] pajoye@php.net

Which settings were used when you get these results? simply use ini_set
to fetch them.

------------------------------------------------------------------------
[2010-06-14 12:48:02] xiaobo dot bob at gmail dot com

i just changed the number several time, larger or zero, but i don't know
which takes the effects.

i think the problem is in the function "number_format".
now in my envirentment, 
"echo number_format(17.0,0)" is correct, result: 17
"echo number_format(17.0,1)" is wrong, result: 16.:
"echo number_format(17.0,3)" is wrong, result: 16.:00

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


The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at

    http://bugs.php.net/bug.php?id=47304


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


Thread (35 messages)

« previous php.bugs (#152283) next »