|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2007-01-30 07:13 UTC] bjori@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2026 The PHP GroupAll rights reserved. |
Last updated: Sun Jun 14 12:00:01 2026 UTC |
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 )