Java Number Format formatNumberWithSameWidth(int d)

Here you can find the source of formatNumberWithSameWidth(int d)

Description

format Number With Same Width

License

Open Source License

Declaration

public static String formatNumberWithSameWidth(int d) 

Method Source Code

//package com.java2s;

public class Main {
    public static String formatNumberWithSameWidth(int d) {
        return formatNumberWithSameWidth(d, String.valueOf(d).length());

    }//  w ww  . j  a  va 2s  .c  om

    public static String formatNumberWithSameWidth(int d, int width) {

        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < width; i++) {
            sb.append("0");
        }
        sb.append(d);
        String s = sb.toString();
        return s.substring(s.length() - width);

    }
}

Related

  1. formatNumberFloorWithPostfix(int value)
  2. formatNumberImpl(long i, int digits, String fill)
  3. formatNumbers(final int... numbers)
  4. formatNumberWithExtension(int num)
  5. formatNumberWithKSeparators(int value)
  6. formatOnlyLettersNumbersAndSpaces(String keyword)
  7. formatPaddedNumber(long number, int numericPadding)
  8. formatPartialName(String name, int numberOfCharacters)
  9. formatPattern(String number, String pattern)