static public String formatBytes(long bytes){
  double val=0;
  String units="";
  if (bytes < 1024) {
    val=bytes;
    units="bytes";
  }
 else   if (bytes < 1048576) {
    val=(bytes / 1024.0f);
    units="KB";
  }
 else   if (bytes < 1073741824) {
    val=(bytes / 1048576.0f);
    units="MB";
  }
 else {
    val=(bytes / 1073741824.0f);
    units="GB";
  }
  DecimalFormat df=new DecimalFormat("###.##");
  return df.format(val) + " " + units;
}

static public String formatBytes ( long bytes ) { double val = 0 ; String units = "" ; if ( bytes < 1024 ) { val = bytes ; units = "bytes" ; } else if ( bytes < 1048576 ) { val = ( bytes / 1024.0f ) ; units = "KB" ; } else if ( bytes < 1073741824 ) { val = ( bytes / 1048576.0f ) ; units = "MB" ; } else { val = ( bytes / 1073741824.0f ) ; units = "GB" ; } DecimalFormat df = new DecimalFormat ( "###.##" ) ; return df . format ( val ) + " " + units ; }
returns a formatted string representation of the number of bytes specified . the largest suitable suffix up until gb will be used , with the returned value expressed to two decimal places .
