title: How do I pad a printf to take account of negative signs and variable length numbers?
body: <p>I'm trying to output some numbers in a log file and I want to pad a load of floats via the <code>printf</code> function to produce:</p>
  
  <pre><code> 058.0
   020.0
   038.0
  -050.0
   800.0
   150.0
   100.0
  </code></pre>
  
  <p>Currently I'm doing this:</p>
  
  <pre><code>printf("% 03.1f\n", myVar);
  </code></pre>
  
  <p>...where myVar is a float. The output from that statement looks like this:</p>
  
  <pre><code>58.0
  20.0
  38.0
  -50.0
  800.0
  150.0
  100.0
  </code></pre>
  
  <p>From <a href="http://www.cplusplus.com/reference/clibrary/cstdio/printf/" rel="noreferrer">what I've read</a> I would expect my code to produce the output I mentioned at the top of this post, but clearly something is wrong. Can you only use one flag at a time? ..or is there something else going on here?</p>