Is a float a whole number?
How do I determine if a float is a whole number (ie has nothng after the decimal place)?
I need to know if the result of my sqrt returns a whole number...
Thanks
Chris
Chris Brodie
I don''t think the last answer will always work the way you expect, as there can be precision errors with floats, in that you might do some integer arithmetic (such as sqrt(25)) and end up with 5.00000000000001 or whatever. So, instead of ==0, perhaps you could perhaps use <0.000001 && >-0.000001.
Anyway, what makes "return (x-(int)x)==0;" better than "return (x == (int)x)"?
Anyway, what makes "return (x-(int)x)==0;" better than "return (x == (int)x)"?
How about
bool IsWholeSqrt( int startNum )
{
if( ( (int)sqrt( startNum )* (int)sqrt( startNum )) == startNum )
return true;
}
People might not remember what you said, or what you did, but they will always remember how you made them feel.
Mad Keith the V.
bool IsWholeSqrt( int startNum )
{
if( ( (int)sqrt( startNum )* (int)sqrt( startNum )) == startNum )
return true;
}
People might not remember what you said, or what you did, but they will always remember how you made them feel.
Mad Keith the V.
It's only funny 'till someone gets hurt.And then it's just hilarious.Unless it's you.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement