FMOD in PHP results not being seen as equal to their float equivalent

58 views Asked by At

So I understand that FMOD gives some wacky answers sometimes because its sort of approximate. But even given that I'm struggling to utilize the answers it throws up later-on in the code.

For instance, fmod(16,1.6) gives us 1.6 rather than 0, that's fine. In the following code, echoing $goodfit prints 1.6 but hurray doesn't print.

$getLength = 16;
$goodFit = fmod($getLength, 1.6);
echo $goodFit;
if ($goodFit === 1.6){
    echo hurray;
}

I've tried double equation signs instead of triple incase it was a data type problem and I've tried rounding the $goodfit equation to one decimal place.

All seems a little odd. I'm just trying to make a bit of code that triggers if a division was exact.

0

There are 0 answers