Java Long Number Readable Format toHumanSize(long bytes)

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

Description

to Human Size

License

Open Source License

Declaration

public static String toHumanSize(long bytes) 

Method Source Code

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

public class Main {
    private static String[] units = { "B", "KB", "MB", "GB", "TB", "PB" };

    public static String toHumanSize(long bytes) {
        int unit = 0;
        double value = bytes;
        while (value > 4096) {
            value = value / 1024;/*from   ww w. j  a  v  a  2  s  .co  m*/
            unit++;
        }
        if (unit == 0) {
            return String.valueOf(bytes) + units[unit];
        }
        return String.format("%.1f%s", value, units[unit]);
    }
}

Related

  1. stringForBytes(long bytes)
  2. stringify(long byteNumber)
  3. toHuman(long amount)
  4. toHumanReadableSize(long byteCount)
  5. toHumanReadableSize(long bytes)
  6. toKilobytes(long bytes)
  7. toLocalizedInteger(long value)
  8. toMB(long b)
  9. toMB(long bytes)