title: C formatted string - How to add leading zeros to float and int values?
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/2486410/extra-leading-zeros-when-printing-float-using-printf">Extra leading zeros when printing float using printf?</a>  </p>
  </blockquote>
  
  
  
  <p>I'm trying to get the output of this C program to have placeholder zeros, as the output of this program will be used as input for another program. Right now, I'm using the following print line.</p>
  
  <pre><code>fprintf(fp1, "06 BR%d%d   %3.4f%3.4f%3.4f\n",i,d,X,Y,Z);
  
  i = index for the loop
  d = index for a second loop
  X = double for a Cartesian system
  Y = double for a Cartesian system
  Z = double for a Cartesian system
  </code></pre>
  
  <p>Right now the output looks like this:</p>
  
  <pre><code>06 BR12   1.00001.00001.0000
  </code></pre>
  
  <p>I want it to be like the following:</p>
  
  <pre><code>06 BR0102   001.0000001.0000001.000
  </code></pre>
  
  <p>I know that I could just add placeholding zeros manually (if i&lt;10, add a placeholder, etc.) but is there a more efficient way to output a placeholder zero than simply adding them in if-statements?</p>
  
  <p>Thank you in advance. </p>