/**
* 文件大小格式
* @return
*/
public String fileSizeName(String num){
Double aDouble = Double.valueOf(num) / 1024;
Double number;
//保留两位小数
DecimalFormat df = new DecimalFormat("#0.00");
if (aDouble > 0 && aDouble < 1024){
number = aDouble;
return df.format(number) + "KB";
}
if(aDouble >= 1024 && aDouble < 1048576) {
number = aDouble / 1024;
return df.format(number) + "MB";
}
if (aDouble >= 1048576 && aDouble <= 1073741824){
number = aDouble / 1024 / 1024;
return df.format(number) + "GB";
}
return null;
}
换算
1B(字节)=8b(位)
1 KB = 1024 B
1 MB = 1024 KB
1 GB = 1024 MB
1TB = 1024GB