Edit report at http://bugs.php.net/bug.php?id=47304&edit=1
ID: 47304 Comment by: xiaobo dot bob at gmail dot com 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: 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"; Previous Comments: ------------------------------------------------------------------------ [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] paj...@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 ------------------------------------------------------------------------ [2010-06-14 10:39:00] paj...@php.net xiaobo dot bob at gmail dot com: Which setting do you use for "precision" and "serialize_precision"? ------------------------------------------------------------------------ [2010-06-14 10:37:04] xiaobo dot bob at gmail dot com 2010-06-14 09:30:45 BST I have reproduced this bug, but after changed some setting: change the "precision" and "serialize_precision" setting in php.ini, and even changed back, or maybe after i added the printf("%.2f\n",$v2), the echo $v2 is correctted, but the printf result is always 16.: finally, i wrote such a script: for ($i=0; $i<400; $i++) { echo $i."-"; printf("%f\n",$i); } and found there're 8 number have this bug, they are: 17 19 29 39 170 190 290 390 I'm using windows xp in a virtualbox virtual machine, and a delphi component named php4delphi, the php version is 5.2.13 ------------------------------------------------------------------------ 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