X-FeedAbuse: http://nntpfeed.proxad.net/abuse.pl feeded by 78.192.65.63 Path: csiph.com!usenet.pasdenom.info!nntpfeed.proxad.net!news.muarf.org!news.roellig-ltd.de!open-news-network.org!border2.nntp.ams1.giganews.com!nntp.giganews.com!newsfeed.xs4all.nl!newsfeed2a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.002 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'float': 0.05; 'width': 0.07; 'received:internal': 0.09; 'subject:string': 0.09; 'valueerror': 0.09; 'message-id:@webmail.messagingengine.com': 0.16; 'old-style': 0.16; 'received:10.202': 0.16; 'received:10.202.2': 0.16; 'received:66.111': 0.16; 'received:66.111.4': 0.16; 'received:messagingengine.com': 0.16; 'width,': 0.16; 'wrote:': 0.16; 'skip': 0.18; '>>>': 0.20; 'skip:" 30': 0.20; '(or': 0.21; 'trying': 0.22; 'either.': 0.22; 'header :In-Reply-To:1': 0.24; 'mon,': 0.24; 'equivalent': 0.27; 'specify': 0.27; 'decimal': 0.29; 'code': 0.31; 'subject:?': 0.34; 'skip:- 10': 0.34; 'to:addr:python-list': 0.35; 'clear': 0.35; 'unknown': 0.35; 'but': 0.36; 'alone': 0.36; 'received:10': 0.37; "didn't": 0.37; 'display': 0.37; 'subject:: ': 0.37; 'received:66': 0.38; 'does': 0.39; 'to:addr:python.org': 0.39; 'subject:the': 0.40; 'why': 0.40; 'field': 0.60; 'from:no real name:2**0': 0.61; 'header:Message-Id:1': 0.62 DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=fastmail.us; h= content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-sasl-enc :x-sasl-enc; s=mesmtp; bh=bjXATN/d+h/MO7lNdc7UG9nl6dQ=; b=Y/qTm1 xvR7P1p1mUNTgNKLDXI9wqPp+38UBNqcaDHg7ndmTSv6EKRgdxEnqjyLNC1gxZWg fr9rnrUuP6CUFW6MUVF93YUmoN8R9fnqRDi+fYsAllwPuK/FTCDNoq870ngK1QQ6 1yMiLqZVbFQT8CBJVM8q22bz79dTVqyMlzgdU= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d= messagingengine.com; h=content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-sasl-enc:x-sasl-enc; s=smtpout; bh=bjXATN/d+h/MO7l Ndc7UG9nl6dQ=; b=oo2M0+kVkJARYV2jYYMPMZ6QKmxbkkEOL9cuyy6tuS1i+VN dE3IfikRKcEcFUDoJ/Bg1JTfvoBcUDdno6IIrzSTw3gq9V6+fti6i/IrVtn14ZHv 8+UCKGEXsYQLdTz/dz4eUkU09HnopEPSspvNUTsrwMpPex9uSzFKv7xeD3s0= X-Sasl-Enc: SpbAaUJJchOxhwdGm4xW+ARv/bb9KrbZf9Zws1eHZLFz 1433796724 From: random832@fastmail.us To: python-list@python.org MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain X-Mailer: MessagingEngine.com Webmail Interface - ajax-b076c697 In-Reply-To: References: Subject: Re: Cheat sheet for the new string formatting? Date: Mon, 08 Jun 2015 16:52:04 -0400 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.20+ Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 24 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1433796726 news.xs4all.nl 2888 [2001:888:2000:d::a6]:52451 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:92349 On Mon, Jun 8, 2015, at 16:32, Skip Montanaro wrote: > This is counterintuitive: > > >>> "{:.3}".format(-0.00666762259822) > '-0.00667' > >>> "{:.3f}".format(-0.00666762259822) > '-0.007' > >>> "%.3f" % -0.00666762259822 > '-0.007' > >>> "{:.3s}".format(-0.00666762259822) > ValueError Unknown format code 's' for object of type 'float' > > Why does the first form display five digits after the decimal point? Because it's three significant figures. Using .3 alone with a float is equivalent to %.3g, not %.3f > Why don't floats support "{:.Ns}"? (I know I can use "{!s}".) Why would they? The old style didn't support %.Ns either. If you want a width like "%50s" it's {!s:50}. But if you're using !s (or %s with the old style) you don't get to specify the significant digits, only the field width, so it's not clear what old-style code you're trying to find an equivalent to.