I have a problem with PHP comparing after I divide a value float and integer.
Here my code :
<?php
function test_promo($price) {
$tmpprice = $price*100;
$divprice = $tmpprice/intval($tmpprice);
if ( $divprice > 1 ) {
echo "$price = TRUE
";
//TODO do something >1
}
else {
echo "$price = FALSE
";
//TODO do something <=1
}
}
echo "<pre>";
test_promo(2.41); //output--> 2.41 = FALSE
test_promo(2.42); //output--> 2.42 = FALSE
test_promo(2.43); //output--> 2.43 = TRUE
test_promo(2.44); //output--> 2.44 = FALSE
test_promo(2.45); //output--> 2.45 = TRUE
test_promo(2.46); //output--> 2.46 = FALSE
test_promo(2.47); //output--> 2.47 = TRUE
test_promo(2.48); //output--> 2.48 = FALSE
test_promo(2.49); //output--> 2.49 = TRUE
echo "</pre>";
?>
As you can see the result must be all FALSE but it's not :S
Is it a bug in PHP or just only my computer (Ubuntu x64) has this bug?
SOLUTION :
As the corrected answer below, I need to get only float number as define (the number after .
) like this $divprice = number_format( $newprice/intval($newprice), 2 );