Java Number Format formatNumber(int number, int zeros)

Here you can find the source of formatNumber(int number, int zeros)

Description

format Number

License

Open Source License

Declaration

private static String formatNumber(int number, int zeros) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    private static String formatNumber(int number, int zeros) {
        String strZeros = repeatString("0", zeros);
        String strNumber = Integer.toString(number);
        return new StringBuilder().append(strZeros.substring(0, zeros - strNumber.length())).append(strNumber)
                .toString();//from  w  w  w  . j  av a  2  s.  c  om
    }

    private static String repeatString(String string, int times) {
        StringBuilder builder = new StringBuilder();
        for (int i = 0; i < times; ++i)
            builder.append(string);
        return builder.toString();
    }
}

Related

  1. formatNumber(final long number)
  2. formatNumber(final String number)
  3. formatNumber(final StringBuilder buf, final long number)
  4. formatNumber(float num, int fragmentSize)
  5. formatNumber(int number)
  6. formatNumber(int theNumber, int theNumberOfDigits)
  7. formatNumber(int value, int width, char c)
  8. formatNumber(Integer i, int bisectNumber)
  9. FormatNumber(Integer pNumber, int tolLen)