如何修复RAM格式大小?

时间:2018-05-31 11:58:08

标签: java android ram

如果RAM超过1 GB,则表示没有显示确切的RAM。

Screen capture of the app with text like "Used: 1KB MB"

我如何重新格式化?

 public static String formatSize(long size) {
    String suffix = null;

    if (size >= 1024) {
        suffix = " KB ";
        size /= 1024;
        if (size >= 1024) {
            suffix = " MB ";
            size /= 1024;
        }
    }

1 个答案:

答案 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);
    }