When I run this code:
$value = log(1000, 100);
echo $value;
if ($value == 1.5) {
echo 'Equal';
} else {
echo 'Not Equal';
}
I see 1.5Not Equal
. This is very strange because log(1000, 100)
does return 1.5
, but it does not match the if statement.
Why does PHP do this?
CodePudding user response:
If you var_dump
your $value
you will see the result is float(1.4999999999999998)
and that is not equal to 1.5
, you need to use round like:
$value = round(log(1000, 100), 1);
if ($value == 1.5) {
echo 'Equal';
} else {
echo 'Not Equal';
}
Here you can see result.
Reference: