title: How to format a floating number to fixed width in Python
body: <p>How do I format a floating number to a fixed width with the following requirements:</p>
  
  <ol>
  <li>Leading zero if n &lt; 1</li>
  <li>Add trailing decimal zero(s) to fill up fixed width</li>
  <li>Truncate decimal digits past fixed width</li>
  <li>Align all decimal points</li>
  </ol>
  
  <p>For example:</p>
  
  <pre><code>% formatter something like '{:06}'
  numbers = [23.23, 0.123334987, 1, 4.223, 9887.2]
  
  for number in numbers:
      print formatter.format(number)
  </code></pre>
  
  <p>The output would be like</p>
  
  <pre><code>  23.2300
     0.1233
     1.0000
     4.2230
  9887.2000
  </code></pre>