In Java if
only takes boolean values, and integer values aren't converted to boolean.
To achieve what you want, your method should be like this
public boolean stopAtRange(double number, double current, double accuracy)
{
if( Math.abs(current - number) <= accuracy)
{
return true;
}
return false;
}
This work both if current
is bigger or smaller than number
. If you only want to stop if current
is bigger or at least equals to number
, than you should remove the Math.abs
I also suggest to use this version:
public static boolean stopAtRange(double number, double current, double accuracy) {
return Math.abs(current - number) <= accuracy;
}
because it's more compact, and is optimized, for performances as well.