How to print zero-padded floating point numbers in python 2.6.1
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 |
Newsgroups: comp.lang.python
From: Lorenzo Di Gregorio <lorenzo.digrego...@gmail.com>
Date: Wed, 4 Nov 2009 00:04:08 -0800 (PST)
Local: Wed, Nov 4 2009 7:04 pm
Subject: How to print zero-padded floating point numbers in python 2.6.1
Hello, I thought that I could zero-pad a floating point number in 'print' by inserting a zero after '%', but this does not work. I get: print '%2.2F' % 3.5 3.50 print '%02.2F' % 3.5 3.50 How can I get print (in a simple way) to print 03.50? Best Regards, Lorenzo
You must Sign in before you can post messages.
You do not have the permission required to post.
|
 |
Newsgroups: comp.lang.python
From: Lutz Horn <lutz.h...@fastmail.fm>
Date: Wed, 04 Nov 2009 09:25:53 +0100
Local: Wed, Nov 4 2009 7:25 pm
Subject: Re: How to print zero-padded floating point numbers in python 2.6.1
Lorenzo Di Gregorio schrieb: > print '%2.2F' % 3.5 > 3.50 > print '%02.2F' % 3.5 > 3.50 > How can I get print (in a simple way) to print 03.50?
print '%05.2F' % 3.5 Lutz
You must Sign in before you can post messages.
You do not have the permission required to post.
|
 |
Newsgroups: comp.lang.python
From: Chris Rebert <c...@rebertia.com>
Date: Wed, 4 Nov 2009 00:37:52 -0800
Local: Wed, Nov 4 2009 7:37 pm
Subject: Re: How to print zero-padded floating point numbers in python 2.6.1
On Wed, Nov 4, 2009 at 12:04 AM, Lorenzo Di Gregorio
<lorenzo.digrego ...@gmail.com> wrote: > Hello, > I thought that I could zero-pad a floating point number in 'print' by > inserting a zero after '%', but this does not work. > I get: > print '%2.2F' % 3.5 > 3.50 > print '%02.2F' % 3.5 > 3.50 > How can I get print (in a simple way) to print 03.50? >>> print ("%.2f" % 3.5).zfill(5) 03.50 >>> print ("%5.2f" % 3.5).replace(' ','0')
03.50 Cheers, Chris -- http://blog.rebertia.com
You must Sign in before you can post messages.
You do not have the permission required to post.
|
|
|