I would like to format my integers as strings so that, without the sign, they will be zero-padded to have at least two digits.
For example I want
1
-1
10
-10
to be
01
-01
10
-10
Specifically, I want different minimum string lengths for negative numbers (3) and non-negative numbers (2). Simple number padding as detailed here is insufficient. Is this possible?
According to here, you need a space before the type descriptor, so both
'% d'%(1)
and
'{: d}'.format(1)
result in (notice the space)
' 1'
aligning nicely with the result of the above called with -1:
'-1'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With