Java Number Format numberFormat(int i)

Here you can find the source of numberFormat(int i)

Description

number Format

License

Apache License

Declaration

public static String numberFormat(int i) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.text.DecimalFormat;
import java.text.NumberFormat;

public class Main {
    private static final NumberFormat NF = new DecimalFormat("##,###");
    private static final NumberFormat MEM_FMT = new DecimalFormat("##,###.##");

    public static String numberFormat(int i) {
        return NF.format(i);
    }// ww  w. j  av a 2 s. c om

    public static String numberFormat(double d) {
        return NF.format(d);
    }

    private static String format(long bytes) {
        double val = bytes;
        int mag = 0;
        while (val > 1024) {
            val = val / 1024;
            mag++;
        }

        String formatted = MEM_FMT.format(val);
        switch (mag) {
        case 0:
            return formatted + " bytes";
        case 1:
            return formatted + " kb";
        case 2:
            return formatted + " Mb";
        case 3:
            return formatted + " Gb";
        default:
            return "WTF?";
        }
    }
}

Related

  1. formatSmallerNumber(String prefix, String suffix, long amnt, boolean useDecimals)
  2. formatTo2Digit(int number)
  3. NumberFormat(double str, int max, int min)
  4. numberFormat(double value, String format)
  5. numberFormat(int fractionDigits, Locale locale)
  6. numberFormat(int num)
  7. numberFormat(Number number, String... pattern)
  8. numberFormat(String pattern, BigDecimal number)
  9. numberFormat(String pattern, double value)