Im trying to make a tax and tip calculator and whenever the tax comes up it goes 10 or more decimal places and im trying to restrict it to two.

public static void main(String[] args)
    {
        double cost, total, tip, taxtotal, tiptotal, subtotal, grandtotal;
        Scanner myScanner = new Scanner(System.in);
        System.out.print("How much was your meal before tax? $");  //asks the user how much the meal was on the menu
        subtotal = myScanner.nextDouble();
        total = (subtotal * 1.09);  //adding NH food and meals tax of 9% to the total
        taxtotal = (subtotal * 0.09); //will show how much tax is paid
        System.out.print("What percentage would you like to tip? ");
        tip = myScanner.nextDouble();
        tiptotal = (subtotal * (tip / 100)); //the user can chose how much they want to tip on a percentage if flat number they put 0
        grandtotal = (total + tiptotal);
        System.out.println("The cost of your meal was $" + subtotal + ". You paid $" + taxtotal + " in taxes. You will be tipping " + tip + "% for a $" + tiptotal + " in tips making the grand total $" + grandtotal);
    }

any help would be appreciated thanks

found solution my appologies but if it helps

value1 = Math.round(value1*100.0)/100.0;

it wont force it to be 2 decimal places if the number ends up being .80 it will show .8 not a big deal but works for me

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.