@Test public void getLengthStringTest() { assertEquals("lengthStringBytes", "500 B", MathUtils.GetLengthString(500L)); assertEquals("lengthStringKiloBytes", "2.0 KB", MathUtils.GetLengthString(2048L)); assertEquals("lengthStringMegaBytes", "2.0 MB", MathUtils.GetLengthString(2048L * 1024)); assertEquals("lengthStringGigaBytes", "2.0 GB", MathUtils.GetLengthString(2048L * 1024 * 1024)); }
public static String GetLengthString(final long lengthInBytes) { if (lengthInBytes < 1024) return String .format(LocaleUtil.getCurrent(), "%d B", lengthInBytes); double v = lengthInBytes / 1024D; if (v < 1024) return String.format(LocaleUtil.getCurrent(), "%.1f KB", v); v = v / 1024D; if (v < 1024) return String.format(LocaleUtil.getCurrent(), "%.1f MB", v); return String.format(LocaleUtil.getCurrent(), "%.1f GB", v / 1024D); }
MathUtils { public static String GetLengthString(final long lengthInBytes) { if (lengthInBytes < 1024) return String .format(LocaleUtil.getCurrent(), "%d B", lengthInBytes); double v = lengthInBytes / 1024D; if (v < 1024) return String.format(LocaleUtil.getCurrent(), "%.1f KB", v); v = v / 1024D; if (v < 1024) return String.format(LocaleUtil.getCurrent(), "%.1f MB", v); return String.format(LocaleUtil.getCurrent(), "%.1f GB", v / 1024D); } }
MathUtils { public static String GetLengthString(final long lengthInBytes) { if (lengthInBytes < 1024) return String .format(LocaleUtil.getCurrent(), "%d B", lengthInBytes); double v = lengthInBytes / 1024D; if (v < 1024) return String.format(LocaleUtil.getCurrent(), "%.1f KB", v); v = v / 1024D; if (v < 1024) return String.format(LocaleUtil.getCurrent(), "%.1f MB", v); return String.format(LocaleUtil.getCurrent(), "%.1f GB", v / 1024D); }  }
MathUtils { public static String GetLengthString(final long lengthInBytes) { if (lengthInBytes < 1024) return String .format(LocaleUtil.getCurrent(), "%d B", lengthInBytes); double v = lengthInBytes / 1024D; if (v < 1024) return String.format(LocaleUtil.getCurrent(), "%.1f KB", v); v = v / 1024D; if (v < 1024) return String.format(LocaleUtil.getCurrent(), "%.1f MB", v); return String.format(LocaleUtil.getCurrent(), "%.1f GB", v / 1024D); }  static String GetLengthString(final long lengthInBytes); static String GetTimeRemainingString(long timeRemainingMillis); static String GetTimeRemainingOrDateString(final long now,
            final long elapsed,
            final boolean bDate); static String parseTimeRelativeToNow(final String timestamp); static String GetDownloadSpeedString(double averageSpeed); static double log2(final double v); static double parseDouble(String value, double defaultVal); static int parseInt(String value, int defaultVal); }
MathUtils { public static String GetLengthString(final long lengthInBytes) { if (lengthInBytes < 1024) return String .format(LocaleUtil.getCurrent(), "%d B", lengthInBytes); double v = lengthInBytes / 1024D; if (v < 1024) return String.format(LocaleUtil.getCurrent(), "%.1f KB", v); v = v / 1024D; if (v < 1024) return String.format(LocaleUtil.getCurrent(), "%.1f MB", v); return String.format(LocaleUtil.getCurrent(), "%.1f GB", v / 1024D); }  static String GetLengthString(final long lengthInBytes); static String GetTimeRemainingString(long timeRemainingMillis); static String GetTimeRemainingOrDateString(final long now,
            final long elapsed,
            final boolean bDate); static String parseTimeRelativeToNow(final String timestamp); static String GetDownloadSpeedString(double averageSpeed); static double log2(final double v); static double parseDouble(String value, double defaultVal); static int parseInt(String value, int defaultVal);  }