spacemonkey spacemonkey - 7 months ago 22
PHP Question

PHP check if variable is a whole number

I have this PHP code:

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


What i want to know is, how to check whether $entityElementCount is a whole number (2, 6, ...) or partial (2.33, 6.2, ...).

Thank you!

Answer
$entityElementCount = (-($highScore-$totalKeywordCount))/0.29;
if (ctype_digit($entityElementCount) ){
    // (ctype_digit((string)$entityElementCount))  // as advised.
    print "whole number\n";
}else{
    print "not whole number\n";
}
Comments