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
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
[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
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.