Java Long Number Readable Format humanizeBytes(long bytes)

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

Description

humanize Bytes

License

Open Source License

Declaration

public static String humanizeBytes(long bytes) 

Method Source Code

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

public class Main {
    public static String humanizeBytes(long bytes) {
        int unit = 1000; // 1024 for non-SI units
        if (bytes < unit)
            return bytes + " B";
        int exp = (int) (Math.log(bytes) / Math.log(unit));
        return String.format("%.1f %sB", bytes / Math.pow(unit, exp), "kMGTPE".charAt(exp - 1));
    }/*  ww  w  .ja va2  s.  co  m*/
}

Related

  1. getHumanReadableSize(long size, long unit, String unitName)
  2. getHumanSize(long size)
  3. getMaxHeap(String message)
  4. getTrafficString(long bytes)
  5. humanize(long value)
  6. humanNumber(long num)
  7. humanreadable(long bytes, boolean si)
  8. humanReadable(long memory)
  9. humanReadable(long number)