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

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

Description

human Readable Byte Count

License

Open Source License

Declaration

public static String humanReadableByteCount(long bytes, boolean si) 

Method Source Code

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

import java.util.Locale;

public class Main {
    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 = ("KMGTPE").charAt(exp - 1) + "";
        return String.format(Locale.US, "%.1f %sB",
                bytes / Math.pow(unit, exp), pre);
    }/*  w w  w .  ja v a 2  s  .  c om*/
}

Related

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