public static String humanBytes(double bytes,boolean si){
  int base=1024;
  String[] pre=new String[]{"K","M","G","T","P","E"};
  String post="B";
  if (si) {
    base=1000;
    pre=new String[]{"k","M","G","T","P","E"};
    post="iB";
  }
  if (bytes < (long)base) {
    return String.format("%.2f B",bytes);
  }
  int exp=(int)(Math.log(bytes) / Math.log(base));
  int index=exp - 1;
  String units=pre[index] + post;
  return String.format("%.2f %s",bytes / Math.pow((double)base,(double)exp),units);
}

public static String humanBytes ( double bytes , boolean si ) { int base = 1024 ; String [ ] pre = new String [ ] { "K" , "M" , "G" , "T" , "P" , "E" } ; String post = "B" ; if ( si ) { base = 1000 ; pre = new String [ ] { "k" , "M" , "G" , "T" , "P" , "E" } ; post = "iB" ; } if ( bytes < ( long ) base ) { return String . format ( "%.2f B" , bytes ) ; } int exp = ( int ) ( Math . log ( bytes ) / Math . log ( base ) ) ; int index = exp - 1 ; String units = pre [ index ] + post ; return String . format ( "%.2f %s" , bytes / Math . pow ( ( double ) base , ( double ) exp ) , units ) ; }
humanbytes formats bytes as a human readable string .
