Here you can find the source of formatNumber(long number, int digits)
public static String formatNumber(long number, int digits)
//package com.java2s; public class Main { public static String formatNumber(long number, int digits) { return formatNumber(number, digits, '0'); }/*from ww w. ja v a 2 s. c o m*/ public static String formatNumber(long number, int length, char fill) { return formatString(Long.toString(number), length, fill, true); } public static String formatString(String string, int length, char fill, boolean rightAligned) { StringBuilder builder = new StringBuilder(string); while (builder.length() < length) { if (rightAligned) builder.insert(0, fill); else builder.append(fill); } return builder.toString(); } }