Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #7204
| Date | 2011-06-07 18:46 -0700 |
|---|---|
| From | Larry Hudson <orgnut@yahoo.com> |
| Newsgroups | comp.lang.python |
| Subject | Re: Dynamic Zero Padding. |
| References | <BANLkTik3hcA2vVfs3jCnbcRdh3_rKhU3ow@mail.gmail.com> <mailman.5.1307483556.11593.python-list@python.org> <RcxHp.6670$EU5.5710@newsfe17.iad> |
| Message-ID | <ANadncITMO0USXPQnZ2dnUVZ5gmdnZ2d@giganews.com> (permalink) |
On 06/07/2011 03:01 PM, harrismh777 wrote:
> Ethan Furman wrote:
>> --> print("Testing %0*i" % (width, 1))
>
>> The '*' acts as a place holder for the width argument.
>
> very nice...
>
It works for precision as well as width.
wid = 10
prec = 3
num = 123.456789
print "%0*.*f" % (wid, prec, num)
gives you -> 000123.457
(It's the same as the printf() function in C.)
-=- Larry -=-
Back to comp.lang.python | Previous | Next — Previous in thread | Find similar | Unroll thread
Re: Dynamic Zero Padding. Ethan Furman <ethan@stoneleaf.us> - 2011-06-07 15:04 -0700
Re: Dynamic Zero Padding. harrismh777 <harrismh777@charter.net> - 2011-06-07 17:01 -0500
Re: Dynamic Zero Padding. Larry Hudson <orgnut@yahoo.com> - 2011-06-07 18:46 -0700
csiph-web