Java Long Number Readable Format humanReadableByteCount(final long bytes)

Here you can find the source of humanReadableByteCount(final long bytes)

Description

human Readable Byte Count

License

Open Source License

Declaration

public static String humanReadableByteCount(final long bytes) 

Method Source Code

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

public class Main {
    public static String humanReadableByteCount(final long bytes) {
        return humanReadableByteCount(bytes, true);
    }/* w w w .j  a v  a2  s  .  c om*/

    private static String humanReadableByteCount(final long bytes, final boolean si) {
        final int unit = si ? 1000 : 1024;
        if (bytes < unit) {
            return bytes + " B";
        }

        final int exp = (int) (Math.log(bytes) / Math.log(unit));

        final String pre = (si ? "kMGTPE" : "KMGTPE").charAt(exp - 1) + (si ? "" : "i");

        return String.format("%.1f %sB", bytes / Math.pow(unit, exp), pre);
    }
}

Related

  1. humanizeBytes(long bytes)
  2. humanNumber(long num)
  3. humanreadable(long bytes, boolean si)
  4. humanReadable(long memory)
  5. humanReadable(long number)
  6. humanReadableByteCount(final long bytes, final boolean si)
  7. humanReadableByteCount(long bytes)
  8. humanReadableByteCount(Long bytes, boolean decimal)
  9. humanReadableByteCount(long bytes, boolean si)