FastNumberFormat { public static StringBuilder format(StringBuilder sb, long value, int minimumDigits) { if (value < 0) { sb.append('-'); value = -value; } long tmp = value; do { tmp /= 10; } while (--minimumDigits > 0 && tmp > 0); for (int i = minimumDigits; i > 0; --i) { sb.append('0'); } sb.append(value); return sb; }  static StringBuilder format(StringBuilder sb, long value, int minimumDigits);  }
@Test(timeout = 1000) public void testLongWithPadding() throws Exception { NumberFormat numberFormat = NumberFormat.getInstance(); numberFormat.setGroupingUsed(false); numberFormat.setMinimumIntegerDigits(6); long[] testLongs = {1, 23, 456, 7890, 12345, 678901, 2345689, 0, -0, -1, -23, -456, -7890, -12345, -678901, -2345689}; for (long l: testLongs) { StringBuilder sb = new StringBuilder(); FastNumberFormat.format(sb, l, MIN_DIGITS); String fastNumberStr = sb.toString(); Assert.assertEquals("Number formats should be equal", numberFormat.format(l), fastNumberStr); } }