So I’m writing some software and have come across something I haven’t before with regards to a calculation being made incorrectly. Initially I had noticed that one of my floats was actually a string instead, so I converted it to a float (outputs as “double”).
I still feel like it’s a typecasting issue (because if I just output this code alone it’s fine), but when I output the types they are indeed both floats (double) and integers where they should be.
[php]echo “
$amountIn=”.$amountIn." (type:".gettype($amountIn)."), $total=".$total." (type:".gettype($total).") and “;
$NEWamountIn = $amountIn100;
$NEWtotal = $total100;
echo “$NEWamountIn=”.$NEWamountIn.” (type:".gettype($NEWamountIn)."), $NEWtotal=".$NEWtotal." (type:".gettype($NEWtotal).")
";
echo “Which emeans that (type:”.gettype($amountIn).") “.$amountIn.”*100 = “;
$amountIn = intval($NEWamountIn);// Convert to INT
echo $amountIn.” (type:".gettype($amountIn).") and that (type:".gettype($total).") “.$total.”*100 = “;
$total = intval($NEWtotal);// Convert to INT
echo $total.” (type:".gettype($total).").";
if($amountIn != $total) {
echo “WTF? How are they not equal?”;
}[/php]
And here’s what it outputs. (notice the 2nd line has an incorrect calculation)
[sup]$amountIn=220.21 (type:double), $total=220.21 (type:double) and $NEWamountIn=22021 (type:double), $NEWtotal=22021 (type:double)
Which emeans that (type:double) 220.21100 = 22020 (type:integer) and that (type:double) 220.21100 = 22021 (type:integer).WTF? How are they not equal?[/sup]
Am I losing my marbles?