Formats { public static final String formatRate(double rate) { if (rate == 0) { return " 0"; } else if (rate < 100) { return String.format("%5.2f", rate); } else if (rate < 1000) { return String.format("%5.1f", rate); } else if (rate < 100e3) { return String.format("%4.1fk", rate / 1e3); } else if (rate < 100e6) { return String.format("%4.1fm", rate / 1e6); } else if (rate < 100e9) { return String.format("%4.1fg", rate / 1e9); } else { return String.format("%5.1e", rate); } }  static final String toTimestamp(long millis); static final String toDatestamp(long millis); static final String toFileDatestamp(long millis); static final String currentDatestamp(); static final String currentFileDatestamp(); static final String formatRate(double rate); static final String toMemorySize(long n); static void main(String[] args); static final String ZERO_LEAD_DECIMAL_6; static final String DATE_STAMP; static final String FILE_DATE_STAMP; static final String TIME_STAMP; }
@Test public void testformatRate() { assertEquals(" 0", formatRate(0d)); assertEquals("50.00", formatRate(50d)); assertEquals("500.0", formatRate(500d)); assertEquals("50.0k", formatRate(50e3d)); assertEquals("50.0m", formatRate(50e6d)); assertEquals("50.0g", formatRate(50e9d)); assertEquals("1.5e+11", formatRate(150e9d)); }