Note: i think this is not duplicate because same double adding works in another script and not in same script. and these are all double not float, and that question is not related to php, if that's the problem then what could be solution in php.
while both script var_dump same number and type is showing float with same value but calcuation is diffrent in both script.
what could be wrong? is there anything else hidden in double or float which don't get revealed in var_dump?
i know i can round things to fix problem, but why its working in one script and not in another.
i've given full script with simplified version.
full version which don't works https://eval.in/976389
short version which works fine https://eval.in/976394
why both giving different output?
$str="12000,1000,5000,-5000,25000,-10000,-10000,-4000,-10000,-3000,7000,-3000,-3000,-1000,7000,13000,-10000,-7000,-3000,-20,3
2,-1000,1000,2000,1000,-100,-100,-100,-3646,3000,-2000,-19,-9,3000,2000,-38,-2000,-200,-3646,-48,-100,3000,-1000,-1500,
-20,-80,4000,-46,-200,-3646,-183,1000,-67,10000,-7000,-1000,-2000,-500,10000,-4000,-2200,-100,-557.28,-16,1.09,1.05,-50
,-110,2000,-50,-231,-3646,-1000,-30,-50,-50,-110,-30,50,30,-50,-32,110,-28,-52,-32,-32,50,-102,-102,-300";
$numbers=explode(',',$str);
$balance=0;
foreach ($numbers as $number){
$number=doubleval($number);
$l=$balance;
$balance=$balance+$number;
if(strlen(@explode('.',$balance)[1])>2){
var_dump($l);
var_dump($number);
echo $l.' + '.$number."\n";
echo ($l+$number)."\n";die;
}
}