Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
498 views
in Technique[技术] by (71.8m points)

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

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.

question from:https://stackoverflow.com/questions/65906333/fmod-in-php-results-not-being-seen-as-equal-to-their-float-equivalent

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...