把long型別的資料轉換為KB,MB,G
阿新 • • 發佈:2019-02-07
public String FormetFileSize(long file) {
DecimalFormat df = new DecimalFormat("#.00");
String fileSizeString = "";
if (file < 1024) {
fileSizeString = df.format((double) file) + "B";
} else if (fileS < 1048576) {
fileSizeString = df.format((double) file / 1024) + "K";
} else if (fileS < 1073741824) {
fileSizeString = df.format((double) file / 1048576) + "M";
} else {
fileSizeString = df.format((double) file / 1073741824) + "G";
}
return fileSizeString;
}
DecimalFormat df = new DecimalFormat("#.00");
String fileSizeString = "";
if (file < 1024) {
fileSizeString = df.format((double) file) + "B";
} else if (fileS < 1048576) {
fileSizeString = df.format((double) file / 1024) + "K";
} else if (fileS < 1073741824) {
fileSizeString = df.format((double) file / 1048576) + "M";
} else {
fileSizeString = df.format((double) file / 1073741824) + "G";
}
return fileSizeString;
}