Java Zero Format zeroFormattedStr(int number, int length)

Here you can find the source of zeroFormattedStr(int number, int length)

Description

zero Formatted Str

License

Apache License

Declaration

public static String zeroFormattedStr(int number, int length) 

Method Source Code

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

public class Main {
    public static String zeroFormattedStr(int number, int length) {
        return zeroFormattedStr((long) number, length);
    }// ww  w . j a  va  2 s .  c  om

    public static String zeroFormattedStr(long number, int length) {
        String numberStr = String.valueOf(number);
        int size = numberStr.length();
        int additionZeros = length - size;
        if (additionZeros > 0) {
            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < additionZeros; i++) {
                sb.append('0');
            }
            sb.append(numberStr);
            numberStr = sb.toString();
        }
        return numberStr;
    }
}

Related

  1. zeroFill(int num, int size, String character)
  2. zeroFill(int value, int fieldWidth)
  3. zerofill(int x, int desiredWidth)
  4. zeroFillString(String originalString, int numZeros)
  5. zeroFormat(Integer source)
  6. zeroIfNull(Integer i)
  7. zeroIfNull(Integer i)
  8. zeroIfNullStrict(Integer i)
  9. zeroInterval(byte[] x, int start, int end)