Java Integer Format formatInteger(int inInt, int inLen, boolean inComma, int inCommaPos)

Here you can find the source of formatInteger(int inInt, int inLen, boolean inComma, int inCommaPos)

Description

This method is to format the integer.

License

Open Source License

Declaration

public static final String formatInteger(int inInt, int inLen, boolean inComma, int inCommaPos) 

Method Source Code

//package com.java2s;

public class Main {
    /**/* w  w w .ja  v  a 2 s .co m*/
     * This method is to format the integer.
     **/
    public static final String formatInteger(int inInt, int inLen, boolean inComma, int inCommaPos) {
        String outString = "";
        int countComma = 0, tempInt;
        boolean fNegative = false;

        if (inInt < 0) {
            fNegative = true;
            inInt = inInt * (-1);
        }

        if (inInt == 0)
            outString = "0";
        else {
            while (inInt > 0) {

                if (inComma && countComma == inCommaPos) {
                    outString = "," + outString;
                    countComma = 0;
                }

                tempInt = inInt % 10;
                outString = Integer.toString(tempInt) + outString;
                inInt = (int) (inInt / 10);
                countComma++;
            }
        }

        if (fNegative)
            outString = "-" + outString;

        return outString;

    }
}

Related

  1. formatInt64(long val)
  2. formatIntAsDottedOctet(int value)
  3. formatIntAsIpAddress(final int address)
  4. formatInteger(byte[] btValue, int iOffset, int iLength)
  5. formatInteger(int i, int j)
  6. formatInteger(int integer, int length)
  7. formatInteger(int value, int length)
  8. formatInteger(Integer value)
  9. formatIntegerBase2WithLeadingZeros(long x, int length)