我想将总购买量显示为 11.10 而不是 11.1
I want to display the total purchase as 11.10 and not 11.1
输入图书价格:10 美元
图书成本:10.00 美元
征收州税:0.80 美元
征收县税:0.30 美元
总购买价格:11.10 美元
为什么我得到 11.1?
import java.util.Scanner;
public class Program1 {
public static void main(String[] args) {
Scanner kbd = new Scanner(System. in );
double bookCost = kbd.nextDouble();
double stateTax = bookCost * 0.08;
double countyTax = bookCost * 0.03;
double totalCost = bookCost + stateTax + countyTax;
System.out.print("Enter the price of the book: $");
System.out.println();
System.out.println("Book Cost: $" + bookCost);
System.out.println("State Tax Charged: $" + stateTax);
System.out.println("County Tax Charge: $" + countyTax);
System.out.println("Total Purchase Price: $" + totalCost);
}
}
System.out.println( String.format( "%.2f", totalCost ) );
输入图书价格:10 美元
图书成本:10.00 美元
征收州税:0.80 美元
征收县税:0.30 美元
总购买价格:11.10 美元
为什么我得到 11.1?
import java.util.Scanner;
public class Program1 {
public static void main(String[] args) {
Scanner kbd = new Scanner(System. in );
double bookCost = kbd.nextDouble();
double stateTax = bookCost * 0.08;
double countyTax = bookCost * 0.03;
double totalCost = bookCost + stateTax + countyTax;
System.out.print("Enter the price of the book: $");
System.out.println();
System.out.println("Book Cost: $" + bookCost);
System.out.println("State Tax Charged: $" + stateTax);
System.out.println("County Tax Charge: $" + countyTax);
System.out.println("Total Purchase Price: $" + totalCost);
}
}
System.out.println( String.format( "%.2f", totalCost ) );