title: Java - Format a double to currency, values under a dollar omitting the 0
body: <p>first time posting. Sorry if I mess up.</p>
  
  <p>Essentially, code that will return <strong>$2.00</strong> if the value of the double is 2.0, but will return $.75 if the value of the double is .75 (instead of $0.75).</p>
  
  <p>My issue is trying to figure out how to do this. I can use<code>formatter.format(price)</code> but that doesn't omit the leading 0. I can also try to do</p>
  
  <pre><code>String sPrice = String.valueOf(price);
  sPrice = sPrice.replaceFirst("^0+", "");
  </code></pre>
  
  <p>but my issue with that is once I get to that point, I'm making more work for myself when I eventually call to return it, as I'd have to make it to add a 0 if there's only one number after the decimal point.</p>
  
  <p>Here's my full code if you want to look through it, if it helps.</p>
  
  <pre><code>import java.text.*;
  
  public class MenuItem
  {
      private String name;
      private double price;
      private NumberFormat formatter = NumberFormat.getCurrencyInstance();
  
      public MenuItem(String name, double price)
      {
          this.name = name;
          this.price = price;
      }
  
      public String getName()
      {
          return name;
      }
  
      public double getPrice()
      {
          return price;
      }
  
      public String toString()
      {
          return name + " " + formatter.format(price);
      }
  
  }
  </code></pre>
  
  <p>Thanks in advance.</p>