RE: [Tutor] turning a number into a formated string

2004-12-15 Thread Ertl, John
tutor-list (Python) Subject: Re: [Tutor] turning a number into a formated string [Ertl, John] > I need to take a number and turn it into a formatted string. > The final output needs to look like when the X is the > integer part padded on the left and Y is the decimal part padded

Re: [Tutor] turning a number into a formated string

2004-12-15 Thread Marilyn Davis
On Wed, 15 Dec 2004, Tim Peters wrote: > ... return ("%09.4f" % n).replace('.', '') Totally cool. Marilyn ___ Tutor maillist - [EMAIL PROTECTED] http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] turning a number into a formated string

2004-12-15 Thread Tim Peters
[Ertl, John] > I need to take a number and turn it into a formatted string. > The final output needs to look like 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 > some

Re: [Tutor] turning a number into a formated string

2004-12-15 Thread Marilyn Davis
Here's one way: left, right = str(number).split('.') output = "%04d%d" % (int(left), int(right)) + (4 - len(right)) * '0' Maybe someone has a more elegant way. Hope it helps, Marilyn Davis On Wed, 15 Dec 2004, Ertl, John wrote: > I need to take a number and turn it into a formatted string.