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 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 Previous Comments: ------------------------------------------------------------------------ [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 ------------------------------------------------------------------------ [2009-12-23 07:22:24] p dot klein at letsmakesense dot de I experienced this issue using the number_format() and round()-function. My example page displays items in a price list and prices like '17' or '19' (only even numbers) were converted to '16.:' and '18.:'. The weird thing was that every fourth reload the prices were converted correctly to '17,00' and '19,00'. The situation improved after I calculated the floats with BCMath functions. Now three out of four conversions were correct. Next thing I tried was to play with the precision setting of php. After changing the value to '13' the conversion problem disappeared. But even after changing it back to the default setting the issue hasn't occurred anymore. I don't trust the situation. The bug probably still exists, but it's very hard to reproduce. We didn't have the bug while we used version 5.2.0, but it happened with 5.2.12 and 5.3.1. ---------------- Our system: Windows Server 2003 R2, Standard Edition, Service Pack 2 Intel Core 2 CPU 6600 @ 2.40 GHz, 3,99 GB RAM PHP Version 5.2.12 ------------------------------------------------------------------------ [2009-09-28 09:58:07] egorich at junik dot lv Seems that it fixed with rolling back to php 5.2.5 to me. ------------------------------------------------------------------------ [2009-06-22 16:21:28] ciudadsatan at hotmail dot com The bug in Linux happens with echo 0.15-0.05; ------------------------------------------------------------------------ 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