格式System.out.print(String.format("%.保留几位f",对象));
例子
System.out.print(String.format("%.1f",tem1) + " " + String.format("%.1f",tem2));
这篇博客介绍了如何利用Java中的String.format方法来精确控制浮点数的显示,例如保留小数点后一位。通过示例代码System.out.print(String.format(%.1ftem1)++String.format(%.1ftem2)),展示了如何格式化并连接两个浮点数tem1和tem2。
格式System.out.print(String.format("%.保留几位f",对象));
例子
System.out.print(String.format("%.1f",tem1) + " " + String.format("%.1f",tem2));
3633
4526

被折叠的 条评论
为什么被折叠?