I’m looking for a function that tests to see if an integer is a whole number.
So far I’ve got this:
if (is_numeric($answer3)) {
echo "Is triangular\n";
} else {
echo "Is not triangular\n";
}
But this always returns “Is triangular”, even when $answer3 is a decimal.
How can I test an integer to see if it has a decimal?
is_numeric will return true for floats too, considering floats are numeric
You can try is_float(), but if the input is a string it wont work.
So if you are dealing with something that is a string representation of a number then just look for a
.You can add is_numeric if you need to