I create android app for dividing numbers.
int a,b;
int result = a/b;
if (result==decimal){
Log.v (\"result\",\"your result number is decimal\")
} else {
int
will not hold a decimal, they always take the floor of the result: for example 3 / 5 = 0
as an int
. That said you can use modulo (%
) to determine if decimals are being dropped.
if(a % b > 0) { // 3 % 5 = 3
// Decimal places will be lost
}
You can also check if the string contains a .
.
String.parseString(decimalNumber).contains(".");
Use the modulus operator to check if there is a remainder.
if(a % b != 0) Log.v("result", "The result is a decimal");
else Log.v("result", "The result is an integer");