public String size(int size){
String hrSize = \"\";
int k = size;
double m = size/1024;
double g = size/1048576;
double t = size/1073741824;
My basic version (you CAN define some constants instead of computing POW all the time):
public static String GetFolderSizeHuman(long aBytes)
{
if (aBytes < 1024 * 1024)
return aBytes + " KB";
else if (aBytes < Math.pow(2, 20) * 1024)
return (int) aBytes / Math.pow(2, 20) + " MB";
else if (aBytes < Math.pow(2, 30) * 1024 )
return kGbTbFormatter.format(aBytes / Math.pow(2, 30)) + " GB";
else if (aBytes < Math.pow(2, 40) * 1024)
return kGbTbFormatter.format(aBytes / Math.pow(2, 40)) + " TB";
else return "N/A (1TB?)";
}