I am very new to Java and playing with displaying a message with GUI. So if use the console
System.out.printf("Your total montly bill is $%.2f", totalCost);
gives me the output with decimal the way it should. I am trying to do the same thing with this, but I get more digits after the decimal because totalCost is a type double. How can I format the output to only show two digits after the decimal? Thanks.
JOptionPane.showMessageDialog(null, "Your monthly payment is " + totalCost);
You could do: