title: How can I format 2 decimal places in monetary amount?
body: <p>i was assigned a question to design a java program to calculate the price of a pizza, this is what I tried:</p>
  <pre><code>        String diameter;
          diameter = this.txtInput.getText();
          
          // variable declaration and intialize for &quot;labourCost&quot; and &quot;storeCost&quot;
          double labourCost, storeCost;
          labourCost = 1;
          storeCost = 1.5;       
          
          // convert the value inputted from a string to double
          double dblDiameter= Double.parseDouble(diameter);
          
          // variable declarationa and intialize the value for the variable &quot;cost&quot;
          double cost = (labourCost + storeCost + (0.5 * dblDiameter));
          
          // print the output
          this.lblOutput.setText(&quot;The cost of the pizza is $&quot; + cost);
  </code></pre>
  <p>The output I got is $7.5, my question is how can I format it so it will display $7.50? thank you.</p>