Java Number Format formatNumber(String formatStr, int length, boolean leftPadding, char paddingCharacter)

Here you can find the source of formatNumber(String formatStr, int length, boolean leftPadding, char paddingCharacter)

Description

format Number

License

Apache License

Declaration

public static String formatNumber(String formatStr, int length, boolean leftPadding, char paddingCharacter) 

Method Source Code

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

public class Main {

    public static String formatNumber(String formatStr, int length, boolean leftPadding, char paddingCharacter) {
        StringBuilder result = new StringBuilder(formatStr);
        String paddingStr = String.valueOf(paddingCharacter);

        while (result.length() < length) {
            if (leftPadding) {
                result = (new StringBuilder(paddingStr)).append(result);
            } else {
                result.append(paddingCharacter);
            }/*from ww w.ja  va  2 s  .  c  o m*/
        }

        return result.toString();
    }
}

Related

  1. formatNumber(long number, int digits)
  2. formatNumber(long pNum, int pLen)
  3. formatNumber(long value)
  4. formatNumber(Number number)
  5. formatNumber(Object num)
  6. formatNumber(String num, int n)
  7. formatNumber(String s, Character thousandsSeparator, Character decimalSeparator)
  8. formatNumber(String value)
  9. formatNumberFloorWithPostfix(int value)