Basically I have a long list of numbers, that are never greater than 999999, and never have more than 2 decimal places, ie, most numbers look like 123456.78

But I have several numbers in this list that are less than 100000, or have only 1 decimal place, or both.
One example of which is 3434.2

I want to get python to print out this number in the same format as the others, as in i wish it to print out 003434.20

However, I'm having real problems trying to get this to happen via the format conversion specifiers. So far, I can make the second decimal place appear by simply specifying:

b='%.2f' % a
print b

But when I then try to include the zeros at the start, it throws an error because the conversion i found for that


needs the number to be a integer, and won't allow a float. I tried converting this number into an integer to do this operator, and then back to a float again:

c='%08d' % b
print '%.2f' % e

However, when I make the conversion back into a float, it removes the 0's i added at the start, making the whole process pointless.

Anyone know how I can make this conversion correct?


6 Years
Discussion Span
Last Post by Gribouillis
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.