Java Fraction Format formatNumber(double i)

Here you can find the source of formatNumber(double i)

Description

format Number

License

Open Source License

Declaration

public static CharSequence formatNumber(double i) 

Method Source Code


//package com.java2s;
import java.text.NumberFormat;

public class Main {
    public static CharSequence formatNumber(long i) {
        float value = i;
        String suffix;//  w  w w  . j ava 2 s .  c  om
        if (value >= 1000000000) {
            value = value / 1000000000f;
            suffix = "b";
        } else if (value >= 1000000) {
            value = value / 1000000f;
            suffix = "m";
        } else if (value > 1000) {
            value = i / 1000f;
            suffix = "k";
        } else {
            return String.valueOf(i);
        }

        return String.format("%.1f%s", value, suffix);
    }

    public static CharSequence formatNumber(double i) {
        return NumberFormat.getInstance().format(i);
    }
}

Related

  1. formatNormalDouble(double value)
  2. formatNum(double d)
  3. formatNum(double num, int numfracdigits)
  4. formatNum(float value)
  5. formatNumber(double decimal)
  6. formatNumber(double num)
  7. formatNumber(double num)
  8. formatNumber(double number)
  9. formatNumber(double number)