文件大小变换
文件大小转换
public String FormateSize(long size) {
double baseKB = 1024, baseMB = 1024 * 1024, baseGB = 1024 * 1024 * 1024;
String strSize = "";
if (size < baseKB) {
strSize = Long.toString(size) + "B";
} else if (size > baseKB && size < baseMB) {
strSize = Double.toString(size / baseKB).substring(0, 4) + "KB";
} else if (size > baseMB && size < baseGB) {
strSize = Double.toString(size / baseMB).substring(0, 4) + "MB";
} else if (size > baseGB) {
strSize = Double.toString(size / baseGB).substring(0, 4) + "GB";
}
if (strSize.indexOf(".") == 3)
strSize = strSize.replace(".", "");
return strSize;
}
public String FormateSize(long size) {
double baseKB = 1024, baseMB = 1024 * 1024, baseGB = 1024 * 1024 * 1024;
String strSize = "";
if (size < baseKB) {
strSize = Long.toString(size) + "B";
} else if (size > baseKB && size < baseMB) {
strSize = Double.toString(size / baseKB).substring(0, 4) + "KB";
} else if (size > baseMB && size < baseGB) {
strSize = Double.toString(size / baseMB).substring(0, 4) + "MB";
} else if (size > baseGB) {
strSize = Double.toString(size / baseGB).substring(0, 4) + "GB";
}
if (strSize.indexOf(".") == 3)
strSize = strSize.replace(".", "");
return strSize;
}