Is this what you are looking for?
>>> "%07.1f" % 2.11 '00002.1'
So, according to your comment, I can come up with this one (although not so elegant):
>>> fmt = lambda x : "%04d" % x + str(x%1)[1:] >>> fmt(3.1) 0003.1 >>> fmt(3.158) 0003.158
source share