Java Long Number Readable Format readable(long bytes)

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

Description

readable

License

Apache License

Declaration

public static String readable(long bytes) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.text.DecimalFormat;

public class Main {
    private static final long KB = 1024;
    private static final long MB = 1024 * KB;
    private static final long GB = 1024 * MB;

    public static String readable(long bytes) {
        DecimalFormat df = new DecimalFormat("#.###");
        if (bytes >= GB) {
            return df.format((double) bytes / GB) + "GB";
        } else if (bytes >= MB) {
            return df.format((double) bytes / MB) + "MB";
        } else if (bytes >= KB) {
            return df.format((double) bytes / KB) + "KB";
        } else {/*from w w w  .  j  a  v  a  2s  .  c o  m*/
            return bytes + "";
        }
    }
}

Related

  1. humanReadableNumber(long total)
  2. humanReadableSize(long byteCount)
  3. humanReadableSize(long bytes)
  4. humanReadableTime(final long duration)
  5. humanTimeDiff(long timeDiff)
  6. stringForBytes(long bytes)
  7. stringify(long byteNumber)
  8. toHuman(long amount)
  9. toHumanReadableSize(long byteCount)