PHP check if variable is a whole number

后端 未结 20 1217
感动是毒
感动是毒 2020-12-29 20:05

I have this PHP code:

$entityElementCount = (-($highScore-$totalKeywordCount))/0.29;

What i want to know is, how to check whether $

20条回答
  •  心在旅途
    2020-12-29 20:32

    if(floor($number) == $number)
    

    Is not a stable algorithm. When a value is matematically 1.0 the numerical value can be 0.9999999. If you apply floor() on it it will be 0 which is not equals to 0.9999999.

    You have to guess a precision radius for example 3 digits

    if(round($number,3) == round($number))
    

提交回复
热议问题