import java.util.Scanner;
public class CalculatePurchasePrice
{
public static void main(String [] args)
{
Book Cost: $10.00
State Tax Charged: $0.80
County Tax Charged: $0.30
Total Purchase Price: $11.10
Scanner kbd = new Scanner (System.in);
System.out.println("Price of the book: ");
bookPrice = kbd.nextDouble(); // get user input
double staxCharged = bookPrice * stateTax;
System.out.println("State Tax Charged: " + staxCharged);
double ctaxCharged = bookPrice * countyTax;
System.out.println("County Tax Charged: " + ctaxCharged);
totalPP = bookPrice + staxCharged + ctaxCharged;
System.out.println("Total Purchase Price: " + totalPP);
}
}
总计假设显示$ 11.10
总计显示$ 11.1000000000001
答案 0 :(得分:1)
这应该这样做:System.out.printf("总购买价格:%。2f%n",totalPP);
您应该阅读https://docs.oracle.com/javase/tutorial/java/data/numberformat.html