I have two double
values and I want to check for equal or larger and equal or smaller by comparing both values.
I already searched on the internet and also read other related SO questions but couldn't find the solution.
All I could find is, how to compare two double
values,
int returnVal = Double.compare(d1, d2);
But how can I check for d1 <= d2
and d1 >= d2
?
Edit:
double remRangeInKm;
if (remRange == 200 || remRange == 500){
if (remRange == 200) remRangeInKm = 0.2;
else remRangeInKm = 0.5;
}
else remRangeInKm = remRange * 1.0;
int earthRadius = 6371; //in km
double distance = Math.abs(Math.acos(Math.sin(remLatitude)*Math.sin(currentLatitude)
+ Math.cos(remLatitude)*Math.cos(currentLatitude)
* Math.cos(currentLongitude - remLongitude)) * earthRadius);
Log.d("Distance after formula", String.valueOf(distance));
if (distance <= remRangeInKm){
triggerNotification();
}
The distance is 91.482605 meters
and remRangeInKm is 200 meters
even though it's not executing if
statement.