Java Integer Pad Zero zeroPad(int n, int len)

Here you can find the source of zeroPad(int n, int len)

Description

Return a padded string with leading zeros.

License

Open Source License

Parameter

Parameter Description
n Number.
len String length.

Return

Padded string.

Declaration

public static String zeroPad(int n, int len) 

Method Source Code

//package com.java2s;

public class Main {
    /**//from w ww .ja  va 2s.c o  m
     * <p>
     * Return a padded string with leading zeros. 
     * </p>
     * @param n Number.
     * @param len String length.
     * @return Padded string.
     */
    public static String zeroPad(int n, int len) {
        String s = n + "";
        //
        for (int i = len - s.length(); i > 0; i--) {
            s = '0' + s;
        }
        //
        return s;
    }
}

Related

  1. zeroPad(final int amount, final String in)
  2. zeroPad(final int length, final byte[] bytes)
  3. zeropad(final int num, final int size)
  4. zeroPad(int i, int len)
  5. zeroPad(int n, int base, int width)
  6. zeroPad(int number, int places)
  7. ZeroPad(int number, int width)
  8. zeroPad(int value, int padding)
  9. zeroPadArray(byte[] source, int size)