嗨,我尝试在分割字符串生成器并打印该字符串生成器后让我看看我的代码,以进行打印,
string.append("Memomry usage:total:"+totalMemory/1024/1024+ "Mb-used:"+usageMemory/1024/1024+ " Mb("+Percentage+"%)-free:"+freeMemory/1024/1024+ " Mb("+Percentagefree+"%)");
在上面的代码“ totalmemory”和“ freememory”中是双精度类型,其字节值不为空,因此我将其除以“ 1024”两次以在“ Mb”中获得它,“ string”是使用此后的字符串生成器变量代码我只是将其打印出来,结果如下所示,
Used Memory:Memomry usage: total:13.3125Mb-used:0.22920989990234375Mb (0.017217645063086855%) -free:13.083290100097656Mb (0.9827823549369131%)
我想在百分数中以两个小数位表示百分比,并以mb为单位表示已使用和可用内存的值,例如“ used:2345.25”,请记住
希望您的建议
提前致谢
怎么String.format()样
String.format()
System.out.println(String.format("output: %.2f", 123.456));
输出:
output: 123.46