PHP check if variable is a whole number

后端 未结 20 1145
感动是毒
感动是毒 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:29

    Just to share my solution with localized string/number, this combo worked like a charm for me.

    public static function isWholeNumber ($input, $decimalDelimiter = ',')
    {
        if (is_string($input)){
            $input = str_replace($decimalDelimiter, '.', $input);
            $input = floatval($input);
        }
    
        if (fmod($input,1) !== 0.0) {
            return false;
        }
    
        return true;
    }
    

提交回复
热议问题