ID: 40280 Updated by: [EMAIL PROTECTED] Reported By: my-design at gmx dot net -Status: Open +Status: Bogus Bug Type: Documentation problem Operating System: Slackware 11; Kernel 2.6.15.6 PHP Version: Irrelevant New Comment:
Floating point values have a limited precision. Hence a value might not have the same string representation after any processing. That also includes writing a floating point value in your script and directly printing it without any mathematical operations. If you would like to know more about "floats" and what IEEE 754 is read this: http://docs.sun.com/source/806-3568/ncg_goldberg.html Thank you for your interest in PHP. Previous Comments: ------------------------------------------------------------------------ [2007-01-29 22:32:00] my-design at gmx dot net 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 this bug report at http://bugs.php.net/?id=40280&edit=1