Formatting negative fixed-length string
<p>In <code>python</code>, I'm trying to format a number to be a fixed-length string with leading zeros, which can be done like so:</p>

<pre><code>'{:0&gt;10}'.format('10.0040')
'00010.0040'
</code></pre>

<p>I have a negative number and want to express the negative, I would get this:</p>

<pre><code>'{:0&gt;10}'.format('-10.0040')
'00-10.0040'
</code></pre>

<p>If I wanted to format the string to be:</p>

<pre><code>'-0010.0040'
</code></pre>

<p>how could I do this?  </p>

<p>I could do an if/then, but wondering if format would handle this already. </p>

<p>You're problem is that your "number" is being represented as a string, so python has no way of knowing whether it's positive or negative, because it doesn't know it's a number.</p>

<pre><code>&gt;&gt;&gt; '{: 010.4f}'.format(10.0400)
' 0010.0400'
&gt;&gt;&gt; '{: 010.4f}'.format(-10.0400)
'-0010.0400'
</code></pre>

<p>This fills with <code>0</code>'s and has a fixed precision.  It will use a <code>space</code> for positive numbers and a <code>-</code> for negative.</p>

<p>You can change the behavior (i.e. <code>+</code> for positive signs, or just fill with an extra <code>0</code>) using the <a href="https://docs.python.org/2/library/string.html#format-specification-mini-language"><code>sign</code></a> portion of the formatting token</p>

python