Here you can find the source of formatNumber(long i, int digits)
public static String formatNumber(long i, int digits)
//package com.java2s; public class Main { public static String formatNumber(long i, int digits) { return formatNumberImpl(i, digits, "0"); }/* www . j a v a 2 s . co m*/ public static String formatNumberImpl(long i, int digits, String fill) { int ten = 10; String res = ""; while (digits > 1) { if (i < ten) { res += fill; } digits--; ten *= 10; } return res + String.valueOf(i); } }