Click here to Skip to main content
15,892,059 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello, I am making a pizza calculator but my results come out as "$7.5" and not "$7.50". I have this decimal format code written out with my code below it, but it doesn't seem to be doing anything.

can someone please help me?

What I have tried:

DecimalFormat x = newDecimalFormat("0.00");
costOutput.setText("The cost of the pizza is $" + totalCost);
Posted
Updated 5-May-17 1:16am
Comments
Richard MacCutchan 5-May-17 3:13am    
You forgot to specify the format in your setText statement.

1 solution

As @Richard said, you are not using x in the setText statement.

The answer should be
costOutput.setText("The cost of the pizza is $" + x.format(totalCost)); 
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900