Android Long Readable Format prettyBytes(long value)

Here you can find the source of prettyBytes(long value)

Description

pretty Bytes

Declaration

public static String prettyBytes(long value) 

Method Source Code

//package com.java2s;

public class Main {

    public static String prettyBytes(long value) {
        String args[] = { "B", "KB", "MB", "GB", "TB" };
        StringBuilder sb = new StringBuilder();
        int i;/*from   w  w w .ja v a 2 s . c om*/
        if (value < 1024L) {
            sb.append(String.valueOf(value));
            i = 0;
        } else if (value < 1048576L) {
            sb.append(String.format("%.1f", value / 1024.0));
            i = 1;
        } else if (value < 1073741824L) {
            sb.append(String.format("%.2f", value / 1048576.0));
            i = 2;
        } else if (value < 1099511627776L) {
            sb.append(String.format("%.3f", value / 1073741824.0));
            i = 3;
        } else {
            sb.append(String.format("%.4f", value / 1099511627776.0));
            i = 4;
        }
        sb.append(' ');
        sb.append(args[i]);
        return sb.toString();
    }
}

Related

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