Checking if sqrt() result is an integer

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
braveryonions
Forum Newbie
Posts: 14
Joined: Wed Feb 11, 2009 3:31 pm

Checking if sqrt() result is an integer

Post 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?
Mark Baker
Forum Regular
Posts: 710
Joined: Thu Oct 30, 2008 6:24 pm

Re: Checking if sqrt() result is an integer

Post by Mark Baker »

if (floor($value) == $value)
braveryonions
Forum Newbie
Posts: 14
Joined: Wed Feb 11, 2009 3:31 pm

Re: Checking if sqrt() result is an integer

Post by braveryonions »

I can't believe I didn't think of that! Thank you very much!
Post Reply