Here you can find the source of numberToString(int number, int length, String type, int location)
public final static String numberToString(int number, int length, String type, int location)
//package com.java2s; //License from project: Open Source License public class Main { public final static String numberToString(int number, int length, String type, int location) { String numberStr = String.valueOf(number); if (numberStr.length() == length) { return numberStr; } else if (numberStr.length() > length) { return numberStr.substring(numberStr.length() - length); }// w ww . j a v a2s .c om StringBuffer value = new StringBuffer(); for (int i = 0; i < length - numberStr.length(); i++) { value.append(type); } String resStr; if (location == 1) { resStr = numberStr + value.toString(); } else { resStr = value.append(numberStr).toString(); } return resStr; } public final static String numberToString(int number, int length) { String numberStr = String.valueOf(number); if (numberStr.length() == length) { return numberStr; } else if (numberStr.length() > length) { return numberStr.substring(numberStr.length() - length); } StringBuffer value = new StringBuffer(); for (int i = 0; i < length - numberStr.length(); i++) { value.append("0"); } value.append(numberStr); return value.toString(); } }