Java Byte Value Format bytesToHuman(long size)

Here you can find the source of bytesToHuman(long size)

Description

bytes To Human

License

Open Source License

Declaration

public static String bytesToHuman(long size) 

Method Source Code

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

public class Main {
    public static String bytesToHuman(long size) {
        if (size < 1024L) {
            return size + "bytes";
        } else if (size < 1024L * 1024L) {
            return String.format("%.2fkb", (double) size / 1024L);
        } else if (size < 1024L * 1024L * 1024L) {
            return String.format("%.2fmb", (double) size / (1024L * 1024L));
        } else if (size < 1024L * 1024L * 1024L * 1024L) {
            return String.format("%.2fgb", (double) size / (1024L * 1024L * 1024L));
        }//from   w  ww. java 2  s.c om

        return String.format("%.2ftb", (double) size / (1024L * 1024L * 1024L * 1024L));
    }
}

Related

  1. bytesToGB(long bytes)
  2. bytesToHuman(long bytes)
  3. bytesToHumanReadable(int bytes)
  4. bytesToKBytes(long bytes)
  5. bytesToMagaBytes(long bytes)
  6. BytesToMB(long kb)