Android Long Readable Format humanReadableByteCount(long bytes)

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

Description

human Readable Byte Count

Declaration

public static String humanReadableByteCount(long bytes) 

Method Source Code

//package com.java2s;

import java.util.Locale;

public class Main {
    private static final int UNIT = 1024;

    public static String humanReadableByteCount(long bytes) {
        if (bytes < UNIT) {
            return bytes + "B";
        }//  www  . ja  v a 2s.c om
        int exp = (int) (Math.log(bytes) / Math.log(UNIT));
        String pre = String.valueOf("KMGTPE".charAt(exp - 1));
        return String.format(Locale.US, "%.1f%sB",
                bytes / Math.pow(UNIT, exp), pre);
    }
}

Related

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