Android Utililty Methods Int Format

List of utility methods to do Int Format

Description

The list of methods to do Int Format are organized into topic(s).

Method

StringaddCommas(int value)
Adds commas to an integer
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;
StringformatSpeed(int value)
format Speed
return formatSize(value) + "/s";
StringformatSpeed(int speed, String format)
format Speed
java.text.DecimalFormat df = new java.text.DecimalFormat(format);
if (speed < 0)
    return "0B/s";
if (speed < 1000) {
    return speed + "B/s";
if (speed < 1000f * 1024.0)
    return df.format(speed / 1024) + "KB/s";
...
StringgetDecimalFormat(int i, String numStr)
get Decimal Format
try {
    if (numStr != null && !"".equals(numStr)) {
        BigDecimal bd = new BigDecimal(numStr);
        bd = bd.setScale(i, BigDecimal.ROUND_HALF_UP);
        return bd.toString();
    } else {
        return "";
} catch (Exception e) {
    return "";
StringformatGameSize(int size)
format Game Size
DecimalFormat df = new DecimalFormat("0.00");
if (size > 1024 * 1024) {
    return String.valueOf(df.format((float) size / (1024 * 1024)))
            + "M";
} else {
    return String.valueOf(df.format((float) size / 1024)) + "K";
StringformatSpeed(int value)
format Speed
return formatSize(value) + "/s";
StringformatId(String id)
format Id
return String.format("%s-%s-%s-%s", id.substring(0, 4),
        id.substring(4, 8), id.substring(8, 12),
        id.substring(12, 16));
StringformatInt(int number)
format Int
return NumberFormat.getNumberInstance(Locale.US).format(number);