Java Zero Format zeroPrepend(long num, int digits)

Here you can find the source of zeroPrepend(long num, int digits)

Description

Return the string prepended with 0s.

License

Open Source License

Declaration

private static String zeroPrepend(long num, int digits) 

Method Source Code

//package com.java2s;

public class Main {
    private static final String BLOCK_OF_ZEROS = "000000";

    /**//from  ww w  .  j a va  2s.  com
     * Return the string prepended with 0s. Tested as 10x faster than String.format("%06d", ...); Exposed for testing.
     */
    private static String zeroPrepend(long num, int digits) {
        final String hash = Long.toString(num);
        if (hash.length() >= digits) {
            return hash;
        } else {
            final int zeroCount = digits - hash.length();
            final StringBuilder buffer = new StringBuilder(digits).append(BLOCK_OF_ZEROS, 0, zeroCount)
                    .append(hash);

            return buffer.toString();
        }
    }
}

Related

  1. zeroOrderBessel(float num)
  2. zeroOrMore(String... patterns)
  3. zeroOut(byte[] array)
  4. ZeroPoleFilter(float In[], int In_idx, float ZeroCoef[], float PoleCoef[], int PoleCoef_idx, int lengthInOut, int orderCoef, float Out[], int Out_idx)
  5. zeroPrefix(String str, int width)
  6. ZeroRemover(String[] a)
  7. zeros(int n)
  8. zeros(int size)
  9. zerosInt(int len)