test
2022-11-22 本文已影响0人
指下光年
public static String readFileSize(int size){
if(size<=0){
return "0";
}
final String[] units = new String[]{"B","KB","MB","GB","TB"};
int digitGroup = (int)(Math.log10(size)/Math.log10(1024));
double s = size/Math.pow(1024,digitGroup);
return new DecimalFormat("#,##0.#").format(s)+units[digitGroup];
}
public static void main(String[] args) {
String s = readFileSize(52428800);
System.out.println(s);
}