如果RAM超过1 GB,则表示没有显示确切的RAM。
我如何重新格式化?
public static String formatSize(long size) {
String suffix = null;
if (size >= 1024) {
suffix = " KB ";
size /= 1024;
if (size >= 1024) {
suffix = " MB ";
size /= 1024;
}
}
答案 0 :(得分:0)
试试这个
private static String formatSize(long size) {
long Kb = 1024;
long Mb = Kb * 1024;
long Gb = Mb * 1024;
long Tb = Gb * 1024;
long Pb = Tb * 1024;
long Eb = Pb * 1024;
if (size < Kb) return floatForm(size) + " byte";
if (size >= Kb && size < Mb) return floatForm((double) size / Kb) + " Kb";
if (size >= Mb && size < Gb) return floatForm((double) size / Mb) + " Mb";
if (size >= Gb && size < Tb) return floatForm((double) size / Gb) + " Gb";
if (size >= Tb && size < Pb) return floatForm((double) size / Tb) + " Tb";
if (size >= Pb && size < Eb) return floatForm((double) size / Pb) + " Pb";
if (size >= Eb) return floatForm((double) size / Eb) + " Eb";
return "???";
}
private static String floatForm(double d) {
return new DecimalFormat("#.##").format(d);
}