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