Is there a way for mini-languages for this format?
cram a float to 9999 ^ 99 zero padded ^ - implied decimal number.
I did it
for x in (450.5, 50.0, 50.0043, 9999.989,0.5):
print ('{0:06}'.format(round(x,2)).replace('.','')+'000')[0:6]
but I felt a bit dirty afterwords ... so I changed it ...
I know that I can break the float and bring it back together
for x in (450.5, 50.0, 50.0043, 9999.989,0.5, 4):
print '{0:04}{1:0<2}'.format(int(x),int(x % 1 * 100))
it didn't make me feel much better.
I know what I'm doing, but just because I wrote it ...
Who has a great way that is concise and clear? Or is this code clear enough?
source
share