Android Int Format addCommas(int value)

Here you can find the source of addCommas(int value)

Description

Adds commas to an integer

Parameter

Parameter Description
value The integer value

Return

Comma formatted string value of the integer (I.E. 1000 becomes 1,000)

Declaration

public static String addCommas(int value) 

Method Source Code

//package com.java2s;

public class Main {
    /**//w  w w .  ja v  a2  s .c o  m
     * Adds commas to an integer
     * @param value The integer value
     * @return Comma formatted string value of the integer (I.E. 1000 becomes 1,000)
     */
    public static String addCommas(int value) {
        String finalString = "";
        String intStr = "" + value;

        int strCount = intStr.length();
        for (int index = strCount - 1, pointerCount = 0; index >= 0; index--, pointerCount++) {
            if (pointerCount > 0) {
                if (pointerCount % 3 == 0) {
                    finalString = "," + finalString;
                }
            }

            finalString = intStr.charAt(index) + finalString;
        }

        return finalString;
    }
}

Related

  1. formatSpeed(int value)
  2. formatSpeed(int speed, String format)
  3. getDecimalFormat(int i, String numStr)
  4. formatGameSize(int size)