title: Format currency in JavaScript removing .00
body: <p>I am currently formatting numbers to display as currency values using the following code:</p>
  
  <pre><code>return symbol + value.toFixed(2).replace(/(\d)(?=(\d{3})+\.)/g, "$1,");
  </code></pre>
  
  <p>where symbol is £,$ etc. and value is a number with many decimal places. This works great but I now want to remove trailing <code>.00</code> if present. </p>
  
  <p>Currently I have this output:</p>
  
  <pre><code>1.23454 =&gt; £1.23
  1 =&gt; £1.00
  50.00001 =&gt; £50.00
  2.5 =&gt; £2.50
  </code></pre>
  
  <p>I would like the following:</p>
  
  <pre><code>1.23454 =&gt; £1.23
  1 =&gt; £1
  50.00001 =&gt; £50
  2.5 =&gt; £2.50
  </code></pre>
  
  <p>Is there a cleaner way than:</p>
  
  <pre><code>var amount = symbol + value.toFixed(2).replace(/(\d)(?=(\d{3})+\.)/g, "$1,");
  return amount.replace(".00", "");
  </code></pre>
  
  <p>or is that solution the best way?</p>