Page 1 of 1

Checking if sqrt() result is an integer

Posted: Wed Mar 11, 2009 6:41 pm
by braveryonions
In a script I am working on, I need to check if the output of sqrt() is an integer. I thought this would work with is_int(), but it is always returning false. var_dump() reveals the problem: sqrt() is always returning a float number, even if it's actually an integer. This causes is_int() to return false. How can I check if these float variables are integers?

Re: Checking if sqrt() result is an integer

Posted: Wed Mar 11, 2009 6:51 pm
by Mark Baker
if (floor($value) == $value)

Re: Checking if sqrt() result is an integer

Posted: Wed Mar 11, 2009 6:53 pm
by braveryonions
I can't believe I didn't think of that! Thank you very much!