在Java中打印带有2位小数的整数

2022-01-15 00:00:00 format output number-formatting java

在我的代码中,我使用整数乘以 100 作为小数(0.1 是 10 等).你能帮我格式化输出以显示为十进制吗?

in my code i use integers multiplied by 100 as decimals (0.1 is 10 etc). Can you help me to format output to show it as decimal?

推荐答案

int x = 100;
DecimalFormat df = new DecimalFormat("#.00"); // Set your desired format here.
System.out.println(df.format(x/100.0));

相关文章