printf a float value with precision (number of decimal digits) passed in a variable
<p>I can print a float value with precision of 3 decimal digits with</p>

<pre><code>double f = 1.23456;
printf( "%.3f", f );
</code></pre>

<p>Now I have the number of requested decimal digits that is not fixed but stored into a variable</p>

<pre><code>int precision;
precision = atoi( argv[ 1 ] ); // ...just for example
double f = 1.23456;
</code></pre>

<p>How do I print the value of <code>f</code> with the number of decimal digits specified in <code>precision</code> ?</p>

<p>I can programmatically compose the format string for <code>printf</code> but I'm wondering if there is a more simple way to do it.</p>