这里的问题是当我添加amountbeforetax是68.0,税额为14.96时,它给我amountWithTax等于82.96000000000001,但当我加税时金额是14.97或14.95,14.98它给了我正确的值。
这里有什么问题?为什么它会给我这样的结果?
public class Calc {
public static void main(String[] args) {
double discountAmount = 0;
double amountBeforeTax = 0;
double amountWithTax = 0;
double taxAmount = 0;
amountBeforeTax = 68.0;
System.out.println("amountBeforeTax "+amountBeforeTax);
taxAmount = 14.96;
System.out.println("taxAmount "+taxAmount);
amountBeforeTax-= discountAmount;
System.out.println("amountBeforeTax after discount "+ amountBeforeTax);
amountWithTax = amountBeforeTax + taxAmount;
System.out.println("amountWithTax "+ amountWithTax);
}
}