title: How can I format an integer to a specific length in javascript?
body: <p>I have a number in Javascript, that I know is less than 10000 and also non-negative.  I want to display it as a four-digit number, with leading zeroes.  Is there anything more elegant than the following?</p>
  
  <pre><code>if(num&lt;10) num="000"+num;
  else if(num&lt;100) num="00"+num;
  else if(num&lt;1000) num="0"+num;
  </code></pre>
  
  <p>I want something that is built into Javascript, but I can't seem to find anything.</p>