Java Double Number Readable Format humanReadableUnits(double bytes, boolean internationalSystemOfUnits)

Here you can find the source of humanReadableUnits(double bytes, boolean internationalSystemOfUnits)

Description

human Readable Units

License

Open Source License

Declaration

public static String humanReadableUnits(double bytes, boolean internationalSystemOfUnits) 

Method Source Code

//package com.java2s;

public class Main {
    public static String humanReadableUnits(double bytes, boolean internationalSystemOfUnits) {
        int unit = internationalSystemOfUnits ? 1000 : 1024;
        if (bytes <= 0) {
            return ""; // default units for zero value
        } else if (bytes < unit) {
            return "B";
        }//from   w w  w . j a  v  a2  s .  c o m
        int exp = (int) (Math.log(bytes) / Math.log(unit));
        String pre = (internationalSystemOfUnits ? "kMGTPEZY" : "KMGTPEZY").charAt(exp - 1) + "";
        return String.format("%sB", pre);
    }
}

Related

  1. humanBytes(double bytes)
  2. humanBytes(double value)
  3. humanReadableNumber(double n)
  4. humanSize(double size)
  5. toMB(double inB)
  6. toMB(double n)