class Convert {

    @NonNull
    public static String distance2(double m, int precision) {
        if (Double.isNaN(m)) {
            return "";
        } else if (Double.isInfinite(m)) {
            return Double.toString(m);
        } else {
            if (metric) {
                if (m >= 1000) {
                    final String localValue = ConvertUtil.formatDouble(m * 0.001, precision);
                    // Special case for singular units
                    if (localValue.equals("1")) {
                        return "1 kilometer";
                    } else {
                        return localValue + " kilometers";
                    }
                } else {
                    return ConvertUtil.formatInt(m, precision) + " meters";
                }
            } else {
                if (m >= MILE) {
                    // Need max because of float error
                    final double miles = Math.max(1, m * 0.000621371192);
                    final String localValue = ConvertUtil.formatDouble(miles, precision);
                    // Special case for singular units
                    if (localValue.equals("1")) {
                        return "1 mile";
                    } else {
                        return localValue + " miles";
                    }
                } else {
                    return ConvertUtil.formatInt(m * 3.2808399, precision) + " feet";
                }
            }
        }
    }

}