我试图在Java中使用printf截断到第三个小数点,但我一直只到第二个小数点.这是我试图这样做的代码行:
System.out.printf("The speed in ft/sec is %6.2f\n", time);
Run Code Online (Sandbox Code Playgroud)
试试吧%6.3f.格式是
%(before).(after)(type)
6 3 f
6 -> 6 digits before the decimal
3 -> 3 digits AFTER the decimal
Run Code Online (Sandbox Code Playgroud)
试试这个:
System.out.printf("The speed in ft/sec is %6.3f\n", time);
Run Code Online (Sandbox Code Playgroud)
以上将舍入到三位小数(不是"截断"它们).唯一的区别在于点后的值.
| 归档时间: |
|
| 查看次数: |
1412 次 |
| 最近记录: |