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>Use different format i.e. <code>f</code>:</p>

<pre><code>print "%02i,%02i,%05.2f" % (3, 4, 5.66)
                 ^^^^^^
</code></pre>

<p>or with <code>g</code>:</p>

<pre><code>    print "%02i,%02i,%05.3g" % (3, 4, 5.66)
                     ^^^^^^
</code></pre>

<p>But I would stick to <code>f</code>. I guess that's what you trying to do here (<code>g</code> can sometimes use decimal format). More info here: <a href="https://docs.python.org/2/library/stdtypes.html#string-formatting" rel="nofollow">formatting strings with %</a></p>

<pre><code>'f' Floating point decimal format.
'g' Floating point format. Uses lowercase exponential format if exponent is less than -4 or not less than precision, decimal format otherwise.
</code></pre>

python