Java Number Format formatNumber(long i, int digits)

Here you can find the source of formatNumber(long i, int digits)

Description

format Number

License

Open Source License

Declaration

public static String formatNumber(long i, int digits) 

Method Source Code

//package com.java2s;

public class Main {
    public static String formatNumber(long i, int digits) {
        return formatNumberImpl(i, digits, "0");
    }/*  www . j a v  a 2  s . co m*/

    public static String formatNumberImpl(long i, int digits, String fill) {

        int ten = 10;
        String res = "";
        while (digits > 1) {
            if (i < ten) {
                res += fill;
            }
            digits--;
            ten *= 10;
        }
        return res + String.valueOf(i);
    }
}

Related

  1. formatNumber(int number, int zeros)
  2. formatNumber(int theNumber, int theNumberOfDigits)
  3. formatNumber(int value, int width, char c)
  4. formatNumber(Integer i, int bisectNumber)
  5. FormatNumber(Integer pNumber, int tolLen)
  6. formatNumber(long number)
  7. formatNumber(long number, int digits)
  8. formatNumber(long pNum, int pLen)
  9. formatNumber(long value)