I have a wcf method in which I have to calculate the distance between to latitude longitude point. the distance calculator method takes double value as argument. so when I send latitude value =55.68743, .net converts it to 55.6874299999 and I get wrong distance.
Why the value is converting?? does anybody knows how can I solve it??
Here is some code...
public double distance(double lat1, double lon1, double lat2, double lon2)
{
double theta = lon1 - lon2;
double dist = Math.Sin(deg2rad(lat1)) * Math.Sin(deg2rad(lat2)) + Math.Cos(deg2rad(lat1)) * Math.Cos(deg2rad(lat2)) * Math.Cos(deg2rad(theta));
dist = Math.Acos(dist);
dist = rad2deg(dist);
dist = dist * 60 * 1.1515;
dist = dist * 1.609344;
return (dist);
}
public double deg2rad(double deg)
{
return (deg * Math.PI / 180.0);
}
public double rad2deg(double rad)
{
return (rad / Math.PI * 180.0);
}
In the above code, I am calculating distance of two points. lat1=55.68743,lon1=12.50400 lat2=55.68758, lon2=12.50403
when I execute, value of lat1 turns to 55.687429999999999 and lon1 to 12.504.