title: How to use Java's DecimalFormat for "smart" currency formatting?
body: <p>I'd like to use Java's DecimalFormat to format doubles like so:</p>
  
  <pre><code>#1 - 100 -&gt; $100
  #2 - 100.5 -&gt; $100.50
  #3 - 100.41 -&gt; $100.41
  </code></pre>
  
  <p>The best I can come up with so far is:</p>
  
  <pre><code>new DecimalFormat("'$'0.##");
  </code></pre>
  
  <p>But this doesn't work for case #2, and instead outputs "$100.5"</p>
  
  <p>Edit:</p>
  
  <p>A lot of these answers are only considering cases #2 and #3 and not realizing that their solution will cause #1 to format 100 as "$100.00" instead of just "$100".</p>