Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #31294

Re: simple string format question

References <k5guje$ui$1@ger.gmane.org>
Date 2012-10-15 05:29 -0700
Subject Re: simple string format question
From Chris Rebert <clp2@rebertia.com>
Newsgroups comp.lang.python
Message-ID <mailman.2198.1350304201.27098.python-list@python.org> (permalink)

Show all headers | View raw


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.


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

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: simple string format question Chris Rebert <clp2@rebertia.com> - 2012-10-15 05:29 -0700

csiph-web