Java Double Number Readable Format humanReadableNumber(double n)

Here you can find the source of humanReadableNumber(double n)

Description

human Readable Number

License

Open Source License

Declaration

public static String humanReadableNumber(double n) 

Method Source Code

//package com.java2s;

public class Main {
    public static String humanReadableNumber(double n) {
        if (n >= 1e9) {
            return String.format("%d billion", (Math.round(n / 1e9)));
        } else if (n >= 1e6) {
            return String.format("%d million", (Math.round(n / 1e6)));
        } else if (n >= 1e3) {
            return String.format("%d thousand", (Math.round(n / 1e3)));
        } else if (n >= 1) {
            return String.format("%d", (Math.round(n)));
        } else if (n > 0.01) {
            return String.format("%.2f", (n));
        } else { // Cheating.
            return "0.001";
        }/*from  w  w w. j  av a2  s.  co m*/
    }
}

Related

  1. humanBytes(double bytes)
  2. humanBytes(double value)
  3. humanReadableUnits(double bytes, boolean internationalSystemOfUnits)
  4. humanSize(double size)
  5. toMB(double inB)
  6. toMB(double n)