在Java程序中切断第二个零点

时间:2016-02-12 04:33:31

标签: java double

我不确定我的最后一个零被切断的原因是因为我使用的是double而不是float。看起来情况并非如此;但是,当我有一个返回的数字应该是117.50时,我的输出为117.5

    int gridPrice = 0; //collects price for grid number
    double kiloHours = 0.0; //kilowatt hours variable
    double baseKilo = 100.0; //sets hours charged at .50
    double kiloOver = 0.0; /*finds the amount of Kilos over and subtracts 
    for accurate pricing*/
    double kiloPrice = 0.0; //used to get the price or kiloHours
    double totalAmtDue = 0.0; //collects the price due

    System.out.print("How many sets of data do you have to input? ");
    max = GetInput.readLineInt();

    baseKilo = 100 * .50;

    for (i = 1; i <= max; ++i)//loop to gather user info 
    {

        System.out.print("Enter your full name: ");
        name = GetInput.readLine();
        System.out.print("Enter your grid number: ");
        gridNumber = GetInput.readLineInt();
        System.out.print("Enter the number of Kilowatt hours used: ");
        kiloHours = GetInput.readLineDouble();

        kiloOver = kiloHours - 100;    ........}

这只是我的代码的一小段,但正如你所看到的,我已经宣布我的vars为double,所以我没有看到这种情况发生的原因。

感谢您提供任何帮助

0 个答案:

没有答案