Java Number Format formatNumber(long number, int digits)

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

Description

format Number

License

Open Source License

Declaration

public static String formatNumber(long number, int digits) 

Method Source Code

//package com.java2s;

public class Main {
    public static String formatNumber(long number, int digits) {
        return formatNumber(number, digits, '0');
    }/*from   ww  w.  ja v a  2  s. c o  m*/

    public static String formatNumber(long number, int length, char fill) {
        return formatString(Long.toString(number), length, fill, true);
    }

    public static String formatString(String string, int length, char fill, boolean rightAligned) {
        StringBuilder builder = new StringBuilder(string);
        while (builder.length() < length) {
            if (rightAligned)
                builder.insert(0, fill);
            else
                builder.append(fill);
        }
        return builder.toString();
    }
}

Related

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