I am making an IOS calculator app. I want to get if the division of two numbers will give a floating value or an int value. Can any body tell me how to get this?
Thanks.
if you want to know without actually computing a/b, check whether the remainder of a/b is null:
if (fmod(a,b) == 0) {
// integer result
} else {
// floating-point result
}
If the floor()
of a number is equal to that number, it is an integer.
However, beware of floating-point gotchas.