-2
我想讓下面的代碼只顯示四捨五入的小數點後兩位數。 。 。圓整數>小數點後兩位
public class Main {
public static void main(String[] args) {
double gross = 4322.12d;
double tax = 397.04d;
double net = gross - tax;
double fee = gross * 0.30d;
double vat = fee * 0.20d;
double takeHome = net - (fee + vat);
System.out.println("Gross Refund £" + gross);
System.out.println("Tax Deducted £" + tax);
System.out.println("Net Refund £" + net);
System.out.println("Our Fee £" + (fee + vat));
System.out.println("Funds remaining after deductions £" + takeHome);
}
}
看https://docs.oracle.com/javase/7/docs/api/java/text/NumberFormat.html –
使用'printf()',如下所示:'System.out.printf(「Gross Refund£%.2f%n」,gross);' – Andreas