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


Groups > comp.lang.python > #102095

Re: .format won't display my value with 2 decimal places: Why?

Path csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail
From Ian Kelly <ian.g.kelly@gmail.com>
Newsgroups comp.lang.python
Subject Re: .format won't display my value with 2 decimal places: Why?
Date Mon, 25 Jan 2016 09:51:36 -0700
Lines 16
Message-ID <mailman.220.1453740738.15297.python-list@python.org> (permalink)
References <56A1B69F.3040300@gmail.com> <em59031268-5aa7-4141-b0ba-f5de9a9f9261@andromeda>
Mime-Version 1.0
Content-Type text/plain; charset=UTF-8
X-Trace news.uni-berlin.de QGD86v6I2P4MjKmjU9EuuAdcEjOHDotbMqy525G81mxw==
Return-Path <ian.g.kelly@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.006
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'mrab': 0.05; 'method,': 0.07; 'positional': 0.09; 'subject:Why': 0.09; 'example:': 0.10; 'jan': 0.11; 'exception': 0.13; '2016': 0.16; '24,': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'wrote:': 0.16; 'string': 0.17; 'skip:{ 20': 0.18; 'string,': 0.18; '4.0': 0.22; 'second': 0.24; 'header:In-Reply-To:1': 0.24; "doesn't": 0.26; 'message-id:@mail.gmail.com': 0.27; 'values': 0.28; 'raise': 0.29; 'skip:. 10': 0.32; 'received:google.com': 0.35; 'received:209.85': 0.36; 'to:addr:python-list': 0.36; 'subject:?': 0.36; 'pm,': 0.36; 'subject:: ': 0.37; 'being': 0.37; 'method': 0.37; 'received:209.85.213': 0.37; 'received:209': 0.38; 'why': 0.39; 'format': 0.39; 'to:addr:python.org': 0.40; 'subject:with': 0.40; 'price': 0.69; 'subject:value': 0.84; 'to:name:python': 0.84; 'hand,': 0.97
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type; bh=YonstwSTFx+LRWXGKgdmJ73fT2/4Pnol+WCOhumar9E=; b=GwSyA+FeyiDzIQtbtuzA541+KbaLCL6KASujUwXMqa1bGw7nrMZiUuwqRMiCJNzlLU EvA5jgbrSV6ue9znCQodMRfXW/+36M1QRhBYV87/9KNdxay8BhC5HvLOHSfv73x+P+aS rAvYrcPh6cECsJEya/8An1kYv4OiUg5o2NexHiUs64USPGi+5wklLovBSJj8ighBe4Cw 9gEaOcg4jnGGNHIM1kOTsjzX2Rzi6i96m3wMnKjTr0lKZY/4WuyslOoiNTTuocqLcfrT 7EhP/BC0SGR4JBbw6zD902wEvwj9QAejgbcNsh7ON+u1/nnHLAQKs5d8pDv2n0hZVRbM PfzQ==
X-Google-DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:content-type; bh=YonstwSTFx+LRWXGKgdmJ73fT2/4Pnol+WCOhumar9E=; b=OiubYisbu84ZWMbhJBbGDqG1SDAjS5RuRz8eQ3sszggJ0z4GB8paG4dY5zCdiMoqQm 6k2K/g0cjPdN0m0LgbBD+NGxkc50/EPzXT2cR9MMfeuiAnxauPoauMYFjvgIYVxlWdh2 xE6srD5lYCC3w3lCokjBTiyJWrCMDH6yBfwfGiarUMVKON5yZZid4cowKMTj8Sh5bZ/I I6VyNy6YTMK6cL5xEwiLeCizJfdD+T8VmvA57bZeai4I82lD3Z60OSI4ZMjGHowngcTM Pj0r+Y/535zXSL73o7VdJPyNaB432bquEUI+clFfjGZu014/fN+P3VStopatbhnDj2K3 auZw==
X-Gm-Message-State AG10YOTq+mODtAglAQH+MBtLt3ADG98YXYjmjxEeWDSIV9B1Wu9kI00bIcyTEHJnd7tYMqI44C63daey1orKsg==
X-Received by 10.50.131.201 with SMTP id oo9mr17972803igb.68.1453740735668; Mon, 25 Jan 2016 08:52:15 -0800 (PST)
In-Reply-To <em59031268-5aa7-4141-b0ba-f5de9a9f9261@andromeda>
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.20+
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://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 <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Xref csiph.com comp.lang.python:102095

Show key headers only | View raw


On Sun, Jan 24, 2016 at 2:20 PM, MRAB <python@mrabarnett.plus.com> wrote:
> The format method, on the other hand, belongs to the format string it's
> attached to. In this example:
>
>     'The new price is {}' .format(newPrice, '.2f')
>
> the format string is 'The new price is {}' and you're calling its 'format'
> method with 2 values for that string, the first being 4.0 (used) and the
> second on being '.2f' (unused).
>
> What you want is:
>
>     print('The new price is {:.2f}'.format(newPrice))

Why doesn't str.format raise an exception when passed extra positional
arguments?

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


Thread

Re: .format won't display my value with 2 decimal places: Why? Ian Kelly <ian.g.kelly@gmail.com> - 2016-01-25 09:51 -0700

csiph-web