<p>I keep stumbling on the format specifiers for the printf() family of functions.  What I want is to be able to print a double (or float) with a maximum given number of digits after the decimal point.  If I use:</p>

<pre><code>printf("%1.3f", 359.01335);
printf("%1.3f", 359.00999);
</code></pre>

<p>I get</p>

<pre><code>359.013
359.010
</code></pre>

<p>Instead of the desired</p>

<pre><code>359.013
359.01
</code></pre>

<p>Can anybody help me?</p>

To get rid of the trailing zeros, you should use the "%g" format:
```
```
float num = 1.33;
printf("%g", num); //output: 1.33
```
```
After the question was clarified a bit, that suppressing zeros is not the only thing that was asked, but limiting the output to three decimal places was required as well. I think that can't be done with sprintf format strings alone. As
Pax Diablo
pointed out, string manipulation would be required.