title: chop unused decimals with javascript
body: <p>I've got a currency input and need to return only significant digits. The input always has two decimal places, so:</p>
  
  <pre><code>4.00  -&gt;  4
  4.10  -&gt;  4.1
  4.01  -&gt;  4.01
  </code></pre>
  
  <p>Here's how I'm currently doing it:</p>
  
  <pre><code>// chop off unnecessary decimals
  if (val.charAt(val.length-1) == '0') { // xx.00
      val = val.substr(0, val.length-1);
  }
  if (val.charAt(val.length-1) == '0') { // xx.0
      val = val.substr(0, val.length-1);
  }
  if (val.charAt(val.length-1) == '.') { // xx.
      val = val.substr(0, val.length-1);
  }
  </code></pre>
  
  <p>which works, and has a certain directness to it that I kind of like, but maybe there's a prettier way. </p>
  
  <p>I suppose I could use a loop and run through it three times, but that actually seems like it'll be at least as bulky by the time I conditionalize the if statement. Other than that, any ideas? I imagine there's a regex way to do it, too....</p>