title: Add .00 (toFixed) only if number has less than two decimal places
body: <p>I need to add zeroes, so that each number has at least two decimals, but without rounding.  So for example:</p>
  
  <pre><code>5      --&gt; 5.00
  5.1    --&gt; 5.10
  5.11   --&gt; 5.11 (no change)
  5.111  --&gt; 5.111 (no change)
  5.1111 --&gt;  5.1111  (no change) 
  </code></pre>
  
  <p>My function is missing an IF to check for less than two decimal places:</p>
  
  <pre><code>function addZeroes( num ) {
     var num = Number(num);
     if ( //idk ) {
        num = num.toFixed(2);
     }
     return num;
  }
  </code></pre>
  
  <p>Thanks!</p>
  
  <p>Posting an alternative answer, in addition to the two below.  (Keep in mind that I'm no expert and this is just for text inputs, not for parsing complex values like colors that could have floating point issues, etc.)</p>
  
  <pre><code>function addZeroes( value ) {
      //set everything to at least two decimals; removs 3+ zero decimasl, keep non-zero decimals
      var new_value = value*1; //removes trailing zeros
      new_value = new_value+''; //casts it to string
  
      pos = new_value.indexOf('.');
      if (pos==-1) new_value = new_value + '.00';
      else {
          var integer = new_value.substring(0,pos);
          var decimals = new_value.substring(pos+1);
          while(decimals.length&lt;2) decimals=decimals+'0';
          new_value = integer+'.'+decimals;
      }
      return new_value;
  }
  </code></pre>
  
  <p>[This is not a duplicate question.  The question you linked assumes "knowing that they have at least 1 decimal."  Decimal points cannot be assumed in text inputs, and this was making errors.]</p>