[Tutor] turning a number into a formated string

Ertl, John john.ertl at fnmoc.navy.mil
Wed Dec 15 20:59:31 CET 2004


I need to take a number and turn it into a formatted string.  
The final output needs to look like  XXXXYYYY  when the X is the integer
part padded on the left and  Y is the decimal part padded on the right.
I figured I could split the number at "." and then use zfill or something
like this  (LEVEL1 = "%04d" % LEVEL1) for the XXXX part but I am not sure
how to right pad the decimal part of the number.
Example.
1 and 1.0  needs to look like 00010000 ( I figured I would have to check the
length of the list made from the split to see if a decimal portion existed)
1.1 needs to look like 00011000
22.33 needs to look like 00223330
4444.22 needs to look like 44442200
Any ideas on the right padding the decimal side using "0" 
Thanks,
John 


More information about the Tutor mailing list