Java Long Number Format formatLong(long inLong, int inLen, boolean inComma, int inCommaPos)

Here you can find the source of formatLong(long inLong, int inLen, boolean inComma, int inCommaPos)

Description

This method is to format the long.

License

Open Source License

Declaration

public static final String formatLong(long inLong, int inLen, boolean inComma, int inCommaPos) 

Method Source Code

//package com.java2s;

public class Main {
    /**//from   w  w  w  . j  a v a2 s .c  om
     * This method is to format the long.
     **/
    public static final String formatLong(long inLong, int inLen, boolean inComma, int inCommaPos) {
        String outString = "";
        int countComma = 0;
        long tempLong;
        boolean fNegative = false;

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

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

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

                tempLong = inLong % 10;
                outString = Long.toString(tempLong) + outString;
                inLong = (long) (inLong / 10);
                countComma++;
            }
        }

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

        return outString;

    }

    /**
     * This method is to format the long.
     **/
    public static final String formatLong(long inLong, boolean inComma, int inCommaPos) {
        String outString = "";
        int countComma = 0;
        long tempLong;
        boolean fNegative = false;

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

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

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

                tempLong = inLong % 10;
                outString = Long.toString(tempLong) + outString;
                inLong = (long) (inLong / 10);
                countComma++;
            }
        }

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

        return outString;

    }
}

Related

  1. format(long offsetMillis)
  2. format(long s)
  3. format(long seconds)
  4. format(Long value)
  5. format(long value)
  6. formatLong(Long number)
  7. formatLong(long val, int size)
  8. formatLong(long value)
  9. formatLong(long value)