我是一个 java 新手,试图让我的打印输出语句格式化小数位。我知道 %.2f 有效,但是无论出于何种原因,当我尝试应用 %.2f 时它都会爆炸……不知道是什么做..有什么建议吗?提前致谢!
credits = int
raise = double
System.out.printf("An undergraduate resident student taking " + credits + " currently pays $" + "%,.2f",credtotal);
System.out.println("\n");
System.out.printf("with a increase in tuition of " + (trying to format here) raise + ", per credit will become " + raisecredund + ", and an undergraduate resident taking " + credits + " credits" + " will pay $" +"%,.2f",(credits*(raise*245.73))+ credtotal);;