Java Integer Format formatIntWithPadding(int value, int length, char pad)

Here you can find the source of formatIntWithPadding(int value, int length, char pad)

Description

format Int With Padding

License

Apache License

Parameter

Parameter Description
value a parameter
length a parameter
pad a parameter

Declaration

public static final String formatIntWithPadding(int value, int length, char pad) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

public class Main {
    /**/*from  ww w.j av a2s. co m*/
     * 
     * @param value
     * @param length
     * @param pad
     * @return
     */
    public static final String formatIntWithPadding(int value, int length, char pad) {

        String valueStr = value + "";
        int diff = length - valueStr.length();
        StringBuilder strBuilder = new StringBuilder();

        if (diff > 0) {

            while (diff > 0) {
                diff--;
                strBuilder.append(pad);
            }

            strBuilder.append(valueStr);
            valueStr = strBuilder.toString();

        }

        return valueStr;
    }
}

Related

  1. formatInterval(long interval)
  2. formatIntoHHMMSS(int secsIn)
  3. formatIntoHHMMSS(long l)
  4. formatIntOrLong(long v)
  5. formatInts(int[] vals)