Android Long Readable Format humanReadableByteCount(long bytes, boolean size)

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

Description

human Readable Byte Count

Declaration

public static String humanReadableByteCount(long bytes, boolean size) 

Method Source Code

//package com.java2s;

public class Main {
    public static String humanReadableByteCount(long bytes, boolean size) {
        int unit = size ? 1000 : 1024;
        if (bytes < unit) {
            return bytes + " B";
        }//w w w. j av a  2  s.co m
        int exp = (int) (Math.log(bytes) / Math.log(unit));
        String pre = (size ? "kMGTPE" : "KMGTPE").charAt(exp - 1)
                + (size ? "" : "i");
        return String.format("%.1f %sB", bytes / Math.pow(unit, exp), pre);
    }
}

Related

  1. byteCountToDisplaySize(long size)
  2. humanReadableByteCount(long bytes)
  3. sizeConvert(long size)
  4. prettyBytes(long value)
  5. getSizeDesc(long size)
  6. humanReadableByteCount(long bytes, boolean si)