Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
517 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 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...