#40280 [NEW]: Type casting from float into string

From: Date: Mon, 29 Jan 2007 22:32:00 +0000
Subject: #40280 [NEW]: Type casting from float into string
Groups: php.doc 
Request: Send a blank email to phpdoc+get-969375094@lists.php.net to get a copy of this message
From: my-design at gmx dot net Operating system: Slackware 11; Kernel 2.6.15.6 PHP version: Irrelevant PHP Bug Type: Documentation problem Bug description: Type casting from float into string Description: ------------ Casting from float into string rounds the number without a notice. There seems to be some difference between rounding precision for an string casting and internal float storage precision; that is perhaps not a bug in float handling itself, but is totally unexpected and is a great error source for some scripts. In the above example the value for $x was originally integer 19, stored into the database as float and restored later as given. There is no method to see the difference directly, only in serialised data. Tested PHP versions: 4.4.4 , 4.3.11 Reproduce code: --------------- $x=18.99999999999999289457264239899814128875732421875; print "x=${x}\n"; $a=array(); $a[$x]=$x; print_r($a); Expected result: ---------------- x=18.999999999999 Array ( [18] => 18.999999999999 ) Actual result: -------------- x=19 Array ( [18] => 19 ) -- Edit bug report at http://bugs.php.net/?id=40280&edit=1 -- Try a CVS snapshot (PHP 4.4): http://bugs.php.net/fix.php?id=40280&r=trysnapshot44 Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=40280&r=trysnapshot52 Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=40280&r=trysnapshot60 Fixed in CVS: http://bugs.php.net/fix.php?id=40280&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=40280&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=40280&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=40280&r=needscript Try newer version: http://bugs.php.net/fix.php?id=40280&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=40280&r=support Expected behavior: http://bugs.php.net/fix.php?id=40280&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=40280&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=40280&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=40280&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=40280&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=40280&r=dst IIS Stability: http://bugs.php.net/fix.php?id=40280&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=40280&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=40280&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=40280&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=40280&r=mysqlcfg

« previous php.doc (#969375094) next »