ID: 43053 Comment by: lhfagundes at gmail dot com Reported By: owner at dragon-hearts dot net Status: Verified Bug Type: Scripting Engine problem Operating System: Centos4 PHP Version: 5CVS-2007-10-25 New Comment:
This gets bad if the float is casted to string (which happens if it goes through requests): $x = 1200000000.00; echo $x . "\n"; echo (int)$x . "\n"; $x = "$x"; echo (int) $x . "\n"; In PHP 4.4.2 (I guess in earlier php5 too) 1200000000 1200000000 1200000000 now: 1.2E+9 1200000000 1 Previous Comments: ------------------------------------------------------------------------ [2008-01-28 13:39:47] gcleaves at yahoo dot com dot au Same problem: PHP Version 5.2.4 Windows NT HGCT-SQL 5.2 build 3790 Apache 2.0 Handler ------------------------------------------------------------------------ [2008-01-26 02:18:38] [EMAIL PROTECTED] This issue is still present in PHP 5.2.5 (FreeBSD). It only happens on some floats. If there is a reason for using E-notation in this case - which could be argued, although I feel changing past behavior is not necessary, especially as MySQL has trouble handling these values in common scenarios - it should be made consistent so people can depend on it and prevent problems by testing. <?php echo phpversion() . "\n"; echo 2700000.0; echo "\n"; echo 2800000.0; echo "\n"; echo 2900000.0; echo "\n"; ?> devwh:~> php floats.php 5.2.1 2700000 2800000 2900000 test:~> php floats.php 5.2.4 2700000 2.8E+6 2900000 toms1:~> php floats.php 5.2.5 2700000 2.8E+6 2900000 ------------------------------------------------------------------------ [2008-01-18 21:42:38] nate at recoverydatabase dot net We just got bit by this on one of our servers running Fedora 7 and PHP 5.2.4 installed via yum. The others not causing any headaches are running Fedora 6 and PHP 5.1.6. It's not just a display problem - we have a mysql database with very large values in the primary keys, and when this server tries to insert data, or display, or lookup information based on those values it fails miserably. A php.ini option to disable the notation behavior would be nice. As for right now I must get back to downgrading. :( ------------------------------------------------------------------------ [2007-12-29 01:50:56] daniel at fanetworks dot net I also noticed results coming as scientific notation for larger numbers in 5.1.6. Honestly, it should always come out in interger format with an option to return as notation. Having data not return in a reliable format is a serious issue. Its like $array = array(1=>2, 3=>4); sometimes returning with a serialized version of the array as a string instead of an actual array. Its hard to code when data is returning in an uncontrolled format :( ------------------------------------------------------------------------ [2007-12-01 08:07:06] owner at dragon-hearts dot net I could see it being desireable to have floats come out in normal or scientific format so maybe a php.ini setting would be in order for this. ------------------------------------------------------------------------ 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/43053 -- Edit this bug report at http://bugs.php.net/?id=43053&edit=1