Print leading zeros of a floating point number
<p>I am trying to print something:</p>

<pre><code>&gt;&gt;&gt; print "%02i,%02i,%02g" % (3, 4, 5.66)
03,04,5.66
</code></pre>

<p>However this is not correct. If you notice, the zeroes get correctly pre-pended 
to all the integer floating points (the first two numbers). I need it such that there will be one leading zero if the there is a single digit to the left of the decimal point. </p>

<p>I.e. the solution above should return:</p>

<pre><code>03,04,05.66
</code></pre>

<p>What am I doing wrong?</p>

<p>The format <code>%02g</code> specifies minimum width of 2. You can use <code>%0m.n</code> syntax where <code>m</code> is the minimum width and <code>n</code> is the number of decimals. What you need is this:</p>

<pre><code>&gt;&gt;&gt; print "%02i,%02i,%05.2f" % (3, 4, 5.66)
03,04,05.66
</code></pre>

python