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); if (localValue.equals("1")) { return "1 kilometer"; } else { return localValue + " kilometers"; } } else { return ConvertUtil.formatInt(m, precision) + " meters"; } } else { if (m >= MILE) { final double miles = Math.max(1, m * 0.000621371192); final String localValue = ConvertUtil.formatDouble(miles, precision); if (localValue.equals("1")) { return "1 mile"; } else { return localValue + " miles"; } } else { return ConvertUtil.formatInt(m * 3.2808399, precision) + " feet"; } } } }  static double kts2mps(double knots); @NonNull static String altitude(double m); @NonNull static String distance(double m); @NonNull static String distance(double m, int precision, boolean units); @NonNull static String distance2(double m, int precision); @NonNull static String distance3(double m); @NonNull static String speed(double mps); @NonNull static String speed(double mps, int precision, boolean units); @NonNull static String glide(double glideRatio, int precision, boolean units); @NonNull static String glide(double groundSpeed, double climb, int precision, boolean units); @NonNull static String glide2(double groundSpeed, double climb, int precision, boolean units); @NonNull static String pressure(double hPa); @NonNull static String angle(double degrees); @NonNull static String angle2(double degrees); @NonNull static String bearing2(double degrees); static boolean metric; static final double FT; static final double MPH; static final double KPH; static final float MPHf; static final float KPHf; static final String GLIDE_STATIONARY; static final String GLIDE_LEVEL; static final String GLIDE_VERTICAL; }
@Test public void convertDistance2() { Convert.metric = false; assertEquals("3200 feet", Convert.distance2(1000, 2)); assertEquals("3280 feet", Convert.distance2(1000, 3)); assertEquals("1 mile", Convert.distance2(1609.34, 1)); assertEquals("1.0 miles", Convert.distance2(1609.34, 2)); assertEquals("", Convert.distance2(Double.NaN, 1)); assertEquals("Infinity", Convert.distance2(Double.POSITIVE_INFINITY, 1)); assertEquals("-Infinity", Convert.distance2(Double.NEGATIVE_INFINITY, 1)); }
@Test public void convertDistance2Metric() { Convert.metric = true; assertEquals("990 meters", Convert.distance2(999, 2)); assertEquals("999 meters", Convert.distance2(999, 3)); assertEquals("1 kilometer", Convert.distance2(1000, 1)); assertEquals("1.0 kilometers", Convert.distance2(1000, 2)); }