Latitude/longitude vector to distance, strange problem with output
<p>I have this code to find the distance between two sets of GPS coordinates, I got the code from elsewhere on the net. </p>

<pre><code>function distance($lat1, $lon1, $lat2, $lon2, $unit) { 

  $theta = $lon1 - $lon2; 
  $dist = sin(deg2rad($lat1)) * sin(deg2rad($lat2)) +  cos(deg2rad($lat1)) * cos(deg2rad($lat2)) * cos(deg2rad($theta)); 
  $dist = acos($dist); 
  $dist = rad2deg($dist); 
  $miles = $dist * 60 * 1.1515;
  $unit = strtoupper($unit);

  if ($unit == "K") {
    return ($miles * 1.609344); 
  } else if ($unit == "N") {
      return ($miles * 0.8684);
    } else {
        return $miles;
      }
}
</code></pre>

<p>The ouput returned looks like this: 25.44049 but if I do </p>

<pre><code>$distance_output = distance(-50.12345, 100.1235,-60.12345,120.12345,'km');
echo $distance_output . '&lt;br /&gt;;
echo $distance_output - 15.12345;
</code></pre>

<p>it outputs like this:</p>

<pre><code>15.12345 
1.23639038e10
</code></pre>

<p>These are just made up numbers, but you can see the output of distance() looks like a number but then when I subtract the same number from it, it spits out a wierd exponential number. Any ideas?</p>

<p>Thanks a lot</p>
