title: Ruby: How to add zeros to front of a number string using sprintf()
body: <p>I want to normalize zipcodes to be 5 digits long with zeros replacing any missing characters like so:</p>
  
  <pre><code>"95616" &gt;&gt; "95616"
  "854"  &gt;&gt; "00854"
  "062" &gt;&gt; "00062"
  "0016" &gt;&gt; "00016"
  </code></pre>
  
  <p>I have tried using sprintf like so <code>sprintf("%05s", zipcode)</code> and like so 
  <code>sprintf("%0.5d", zipcode)</code>.  Both give incorrect answers.  Using the <code>s</code>:</p>
  
  <pre><code>"95616" &gt;&gt; "95616"
  "854"   &gt;&gt; "  854"
  "062"   &gt;&gt; "  062"
  "0016"  &gt;&gt; " 0016"
  </code></pre>
  
  <p>This is the correct number of characters, but using spaces, not zeros.  </p>
  
  <p>Using the <code>d</code>:</p>
  
  <pre><code>"95616" &gt;&gt; "95616"
  "854"   &gt;&gt; "00854"
  "062"   &gt;&gt; "00050"
  "0016"  &gt;&gt; "00014"
  </code></pre>
  
  <p>What is the proper use of sprintf() in this case?  </p>