As other posters have indicated, a better question might be to define what "not having a decimal part" means. (Also, I echo their cautions on long doubles.) Which definition is right depends on what you're trying to achieve. I find that "within 1e-6" is often a good definition, but it depends on the situation.
For your specific question, you probably want this:
-(BOOL) numberHasDecimal: (double) n
{
double integerPart = 0.;
if (fabs(modf(n, &integerPart)) > 0.) // has decimal, like 16.300000 or 6453.353259
return YES;
else
return NO; // has no decimal, like 58.000000 or 9274.000000
}
What's going on is that the modf function wants to return the fractional part and store the integer part of the number into another double, the address of which you pass into it. Despite its name, it is not the equivalent of "x % y"; it's really more the equivalent of "return x % 1.0, also storing (x - floor(x)) into the provided pointer" (at least for positive numbers, that is.)
You can think of the second, pointer parameter as a way to return more than one value from a single function call. Even though you don't care, in this case, about the integer part, passing an address for modf to write the integer part into will quiet the compiler and get you the result you're looking for.