我试图在 Java 中使用 printf 截断到第三个小数点,但我总是只得到第二个小数点。这是我尝试执行此操作的代码行:
System.out.printf("The speed in ft/sec is %6.2f\n", time);
最佳答案
尝试使用%6.3f
。格式为
%(before).(after)(type)
6 3 f
6 -> 6 digits before the decimal
3 -> 3 digits AFTER the decimal
关于java - 如何在Java中使用printf限制小数位数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14971745/