Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #31296
| Path | csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <d@davea.name> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.004 |
| X-Spam-Evidence | '*H*': 0.99; '*S*': 0.00; 'value,': 0.03; 'e.g.,': 0.07; 'subject:question': 0.08; 'django,': 0.09; 'subject:string': 0.09; 'cc:addr:python-list': 0.10; 'template': 0.11; '2.00': 0.16; 'columns': 0.16; 'oct': 0.16; 'subject:simple': 0.16; 'temp': 0.16; 'url:djangoproject': 0.16; 'mon,': 0.16; 'string': 0.17; 'wrote:': 0.17; 'specify': 0.17; 'url:dev': 0.17; 'written': 0.20; 'finally,': 0.22; 'cheers,': 0.23; '15,': 0.23; 'seems': 0.23; 'cc:no real name:2**0': 0.24; 'cc:2**1': 0.24; 'tried': 0.25; 'cc:addr:python.org': 0.25; 'header:In-Reply-To:1': 0.25; 'header :User-Agent:1': 0.26; 'am,': 0.27; 'cc:addr:gmail.com': 0.27; 'format,': 0.27; 'actual': 0.28; 'chris': 0.28; 'no,': 0.29; 'probably': 0.29; 'up.': 0.31; 'point': 0.31; 'implement': 0.32; 'project': 0.34; 'there': 0.35; 'add': 0.36; 'created': 0.36; 'but': 0.36; 'should': 0.36; 'uses': 0.37; 'subject:: ': 0.38; 'url:docs': 0.38; 'url:en': 0.38; 'received:192': 0.39; 'space': 0.39; 'received:192.168': 0.40; 'your': 0.60; "you'll": 0.62; 'more': 0.63; 'header:Reply-To:1': 0.68; 'received:74.208': 0.71; 'reply-to:no real name:2**0': 0.72; 'yourself,': 0.75; 'find.': 0.84; 'url:templates': 0.91; 'to:none': 0.93 |
| Date | Mon, 15 Oct 2012 09:02:58 -0400 |
| From | Dave Angel <d@davea.name> |
| User-Agent | Mozilla/5.0 (X11; Linux x86_64; rv:14.0) Gecko/20120714 Thunderbird/14.0 |
| MIME-Version | 1.0 |
| Subject | Re: simple string format question |
| References | <k5guje$ui$1@ger.gmane.org> <CAMZYqRQN3yEkyf=Dd=tPRxti+ztQ4WaQZZWgkAB8pDW+VjHEFQ@mail.gmail.com> |
| In-Reply-To | <CAMZYqRQN3yEkyf=Dd=tPRxti+ztQ4WaQZZWgkAB8pDW+VjHEFQ@mail.gmail.com> |
| Content-Type | text/plain; charset=ISO-8859-1 |
| Content-Transfer-Encoding | 7bit |
| X-Provags-ID | V02:K0:qWVy+4uoCcWK85cTHnKtn+cA27oynLI6V6tHGUXt18p QnX8Qy3PQMu1pD/XrryelO45KuMTaXsMcPW0iQwYl0Pg4nPAPR 0IaugLra3FsfMleoeKrE3axztY0DDU1NUBihIWmOMLadJ5923L w5t+PDcyiIjZt+1DeQH3SsK+nXZUiC+Z4dIOH9b2b3ag/e5qqc C9ZXvWkyx2oFfqpGohZaGk2GKcMUIzMFWnCs1KNqyKhXgpcXe3 tLKxAPGAjHfEi/01CZOZTIe5pJ5GaNe9XLZfBxVQwVVk1dA1Lw uzrnI/WoOCNvU2KgILwbTeIVpvuopFRJ9PUWVI0xmWrC0irqw= = |
| Cc | Neal Becker <ndbecker2@gmail.com>, python-list@python.org |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.15 |
| Precedence | list |
| Reply-To | d@davea.name |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.2201.1350306208.27098.python-list@python.org> (permalink) |
| Lines | 29 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1350306208 news.xs4all.nl 6854 [2001:888:2000:d::a6]:57417 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:31296 |
Show key headers only | View raw
On 10/15/2012 08:29 AM, Chris Rebert wrote:
> On Mon, Oct 15, 2012 at 5:12 AM, Neal Becker <ndbecker2@gmail.com> wrote:
>> Is there a way to specify to format I want a floating point written with no more
>> than e.g., 2 digits after the decimal? I tried {:.2f}, but then I get all
>> floats written with 2 digits, even if they are 0:
>>
>> 2.35 << yes, that's what I want
>> 2.00 << no, I want just 2 or 2.
> Not that I can find. Seems you'll have to implement it yourself.
To do it yourself, probably best to use a temp string value, created by
format "{: f}". (Notice the space before the f, to reserve space for
the sign) Then, slice that value to length 4 . Finally, in your actual
format, use :5s for a format. This should add the blanks for padding,
so other columns still line up.
>
> In the event that your project uses Django, there happens to be a
> template tag for this (pass it -2 in your case):
> https://docs.djangoproject.com/en/dev/ref/templates/builtins/?from=olddocs#floatformat
>
> Cheers,
> Chris
--
DaveA
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: simple string format question Dave Angel <d@davea.name> - 2012-10-15 09:02 -0400
csiph-web