PHP math gets crazy, need explanation, my brain is melting
- by derei
I know that playing with php float can give strange results if you try to add "goats + apples", but please take a look to the following case:
$val = 1232.81;
$p1 = 1217.16;
$p2 = 15.65;
$sum = $p1 + $p2;
$dif = $val - $sum;
echo $dif;
It will give you -2.2737367544323E-13 ... yeah, ALMOST zero, but then why it doesn't say 0 ? This freaks me out big time.
Please, I need some valid explanation.