title: Creating a fixed length output string with sprintf containing floats
body: <p>I'm trying to create a file which has the following structure:<br>
  - Each line has 32 bytes
  - Each line looks like this format string: "%10i %3.7f %3.7f\n"</p>
  
  <p>My Problem is the following: When i have a negative floating point numbers the line gets longer by one or even two characters because the - sign does not count to the "%3.7f".  </p>
  
  <p>Is there any way to do this more nicely than this? </p>
  
  <pre><code>if( node-&gt;lng &gt; 0 &amp;&amp; node-&gt;lat &gt; 0 ) { 
      sprintf( osm_node_repr, "%10i %3.7f %3.7f\n", node-&gt;id, node-&gt;lng, node-&gt;lat );
  } else if (node-&gt;lng &gt; 0 &amp;&amp; node-&gt;lat &lt; 0) {
      sprintf( osm_node_repr, "%10i %3.7f %3.6f\n", node-&gt;id, node-&gt;lng, node-&gt;lat );
  } else if (node-&gt;lng &lt; 0 &amp;&amp; node-&gt;lat &gt; 0) {
      sprintf( osm_node_repr, "%10i %3.6f %3.7f\n", node-&gt;id, node-&gt;lng, node-&gt;lat );
  } else if ( node-&gt;lng &lt; 0 &amp;&amp; node-&gt;lat &lt; 0 ) { 
      sprintf( osm_node_repr, "%10i %3.6f %3.6f\n", node-&gt;id, node-&gt;lng, node-&gt;lat );
  }
  </code></pre>
  
  <p>Thanks for your Answers,<br>
  Andreas</p>