我有一个使用双精度的简单计算,但我得到了一个意想不到的结果,我不明白为什么?
import java.util.Scanner;
public class VersatileSnitSoft {
/**
* @param args
*/
public static void main(String[] args) {
Scanner myScanner = new Scanner(System.in);
double amount;
System.out.print("What’s the price of a CD-ROM? ");
amount = myScanner.nextDouble();
amount = amount + 25.00;
System.out.print("We will bill $");
System.out.print(amount);
System.out.println(" to your credit card.");
}
}
如果我输入 2.99,我得到的结果是..
We will bill $27.990000000000002 to your credit card.