I've had an issue and I've googled the issue and can't find anything relevant with regards to the issue. I'm simply doing addition with two floats but they are evaluating false every time.
Down to the code:
$total = (double)$db['total'];
$postage = (double)$db['postage'];
if (($total - $postage) == 5.95){
$abc = 1;
}elseif(($total - $postage) == 7.95){
$abc = 2;
}elseif(($total - $postage) == 10.95){
$abc = 3;
}else{
$abc = 0;
}
Then the results:
echo $abc; //outputs 0
Total and Postage types before casting to double
echo gettype($db['postage'])." ".gettype($db['total']); // Outputs: string string
Total and Postage after casting
echo gettype($postage)." ".gettype($total); // Outputs: double double
and finally the result of total - postage
echo ($total - $postage); // outputs: 7.95
I've tried with and without casting and tried the value after == in quotation marks but can't seem to find the issue at all. Could anyone point me in the right direction? It's probably something small that I'm missing here.