[Solved] How to determine if result of two integer numbers is integer of float?


you can check it easily with the modulo operator (%), which finds the remainder after the division of one number by another:

if(number1 % number2 == 0) 
{
  // result of division is integral 
  // or in other words: number1 / number2 = whole number
}

Note that number1 and number2 have to be integers in order for modulo to work.

You will also have to cast at least one of your integers to float, in order to get a float as the result of their division.

float result = (float)number1 / number2;

You can read more about the modulo operator here:
https://en.wikipedia.org/wiki/Modulo_operation


EDIT: Incorporated some of the suggestions from the comments below.

9

solved How to determine if result of two integer numbers is integer of float?