Java Long Number Readable Format toHumanReadableSize(long bytes)

Here you can find the source of toHumanReadableSize(long bytes)

Description

to Human Readable Size

License

Open Source License

Declaration

public static String toHumanReadableSize(long bytes) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    public static String toHumanReadableSize(long bytes) {
        boolean si = false;
        int unit = si ? 1000 : 1024;
        if (bytes < unit)
            return bytes + " B";
        int exp = (int) (Math.log(bytes) / Math.log(unit));
        String pre = (si ? "kMGTPE" : "KMGTPE").charAt(exp - 1) + ""; // + (si ? "" : "i");
        return String.format("%.2f %sB", bytes / Math.pow(unit, exp), pre);
    }/*from w  w w. j ava  2s  .c o  m*/
}

Related

  1. readable(long bytes)
  2. stringForBytes(long bytes)
  3. stringify(long byteNumber)
  4. toHuman(long amount)
  5. toHumanReadableSize(long byteCount)
  6. toHumanSize(long bytes)
  7. toKilobytes(long bytes)
  8. toLocalizedInteger(long value)
  9. toMB(long b)