0

I'm not sure if the reason my last zero is being cut off is because I am using double instead of float. It doesn't seem like that would be the case; however, when I have a number returned that should be 117.50, I am getting an output of 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;    ........}

This is just a small snippet of my code but as you can see I have declared my vars as double so I do not see a reason that this is happening.

Thank you for any help you can give

CamronT
  • 25
  • 1
  • 9
  • That's how floating point numbers are printed... So you want something to print like 0.500000000000000? No, probably not, so only 0.5 is printed – OneCricketeer Feb 12 '16 at 04:36
  • You can use formatted output like `System.out.printf("%.2f", d);` where `d` is a `double` or `float` to get two decimal points. – Elliott Frisch Feb 12 '16 at 04:38
  • Thank you for the help Elliott and to Andreas for pointing me in the right direction. – CamronT Feb 12 '16 at 04:44

0 Answers0