package cgeo.geocaching.geopoint;

import cgeo.geocaching.Settings;

public class HumanDistance {
    public static String getHumanDistance(final Float distanceKilometers) {
        if (distanceKilometers == null) {
            return "?";
        }

        if (Settings.isUseMetricUnits()) {
            if (distanceKilometers > 100) {
                return String.format("%d", Math.round(distanceKilometers)) + " km";
            } else if (distanceKilometers > 10) {
                return String.format("%.1f", Double.valueOf(Math.round(distanceKilometers * 10.0) / 10.0)) + " km";
            } else if (distanceKilometers > 1) {
                return String.format("%.2f", Double.valueOf(Math.round(distanceKilometers * 100.0) / 100.0)) + " km";
            } else if (distanceKilometers > 0.1) {
                return String.format("%d", Math.round(distanceKilometers * 1000.0)) + " m";
            } else if (distanceKilometers > 0.01) {
                return String.format("%.1f", Double.valueOf(Math.round(distanceKilometers * 1000.0 * 10.0) / 10.0)) + " m";
            } else {
                return String.format("%.2f", Double.valueOf(Math.round(distanceKilometers * 1000.0 * 100.0) / 100.0)) + " m";
            }
        } else {
            final float miles = distanceKilometers / IConversion.MILES_TO_KILOMETER;
            if (distanceKilometers > 100) {
                return String.format("%d", Math.round(miles)) + " mi";
            } else if (distanceKilometers > 0.5) {
                return String.format("%.1f", Double.valueOf(Math.round(miles * 10.0) / 10.0)) + " mi";
            } else if (distanceKilometers > 0.1) {
                return String.format("%.2f", Double.valueOf(Math.round(miles * 100.0) / 100.0)) + " mi";
            } else if (distanceKilometers > 0.05) {
                return String.format("%d", Math.round(miles * 5280.0)) + " ft";
            } else if (distanceKilometers > 0.01) {
                return String.format("%.1f", Double.valueOf(Math.round(miles * 5280 * 10.0) / 10.0)) + " ft";
            } else {
                return String.format("%.2f", Double.valueOf(Math.round(miles * 5280 * 100.0) / 100.0)) + " ft";
            }
        }
    }
}

@@ -1346,33 +1346,20 @@
     if (
-distanceKilometer
+mile
 s %3E 100)
@@ -1455,33 +1455,20 @@
 lse if (
-distanceKilometer
+mile
 s %3E 0.5)
@@ -1596,33 +1596,20 @@
 lse if (
-distanceKilometer
+mile
 s %3E 0.1)
@@ -1733,43 +1733,82 @@
    %7D
- else if (distanceKilometers %3E 0.05
+%0A%0A            final float feet = miles * 5280;%0A            if (feet %3E= 100
 ) %7B%0A
@@ -1865,22 +1865,12 @@
 und(
-miles * 5280.0
+feet
 )) +
@@ -1904,33 +1904,18 @@
 if (
-distanceKilometers %3E 0.01
+feet %3E= 10
 ) %7B%0A
@@ -1981,36 +1981,28 @@
 (Math.round(
-miles * 5280
+feet
  * 10.0) / 1
@@ -2108,28 +2108,20 @@
 h.round(
-miles * 5280
+feet
  * 100.0

Fix small distances handling in imperial units