Java Long Number Readable Format humanReadableByteCount(long bytes, boolean si)

Here you can find the source of humanReadableByteCount(long bytes, boolean si)

Description

PURPOSE:
humanReadableByteCount

License

Open Source License

Parameter

Parameter Description
bytes a parameter
si a parameter

Return


Declaration

public static String humanReadableByteCount(long bytes, boolean si) 

Method Source Code

//package com.java2s;

public class Main {
    /**/*from w w w  .  j  a v  a2s .com*/
     * PURPOSE: <br>
     * humanReadableByteCount<br>
     * <br>
     *
     * @param bytes
     * @param si
     * @return<br>
     */
    public static String humanReadableByteCount(long bytes, boolean si) {
        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("%.1f %sB", bytes / Math.pow(unit, exp), pre);
    }
}

Related

  1. humanReadable(long number)
  2. humanReadableByteCount(final long bytes)
  3. humanReadableByteCount(final long bytes, final boolean si)
  4. humanReadableByteCount(long bytes)
  5. humanReadableByteCount(Long bytes, boolean decimal)
  6. humanReadableByteCount(long bytes, boolean si)
  7. humanReadableByteCount(long bytes, boolean si)
  8. humanReadableBytes(long bytes)
  9. humanReadableBytes(long bytes)