double x == 2.15;
if(Math.floor(x) == x){
System.out.println("an integer");
} else{
System.out.println("not an integer");
}
I think you can similarly use the Math.ceil()
method to verify whether x
is an integer or not. This works because Math.ceil
or Math.floor
rounds up x
to the nearest integer (say y
) and if x==y
then our original `x' was an integer.