Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #109059
| Path | csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail |
|---|---|
| From | Robin Becker <robin@reportlab.com> |
| Newsgroups | comp.lang.python |
| Subject | Re: str(float) python 3 versus 2.7 |
| Date | Tue, 24 May 2016 15:47:09 +0100 |
| Lines | 16 |
| Message-ID | <mailman.55.1464101239.20402.python-list@python.org> (permalink) |
| References | <7c1af35c-1ac7-96c7-3cba-ab9c8e542d8e@chamonix.reportlab.co.uk> <CALwzidko0E8Pq5158_+G1ufWZtFroC9dsaksusF55fSKW5RWfQ@mail.gmail.com> <38b36519-a231-6d76-bc5e-0e6d5f81808d@chamonix.reportlab.co.uk> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=utf-8; format=flowed |
| Content-Transfer-Encoding | 7bit |
| X-Trace | news.uni-berlin.de 8mTnR9a5Zjq15RvViBLa5wygub/29ycLViuxn/12rLCw== |
| Return-Path | <python-python-list@m.gmane.org> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.000 |
| X-Spam-Evidence | '*H*': 1.00; '*S*': 0.00; 'essentially': 0.04; 'float': 0.05; 'trailing': 0.07; 'type,': 0.07; "'n'": 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'subject:2.7': 0.09; '2.7': 0.13; 'subject:python': 0.14; 'explicitly': 0.15; '2016': 0.16; '23,': 0.16; 'formatting.': 0.16; 'received:80.91.229.3': 0.16; 'received:io': 0.16; 'received:plane.gmane.org': 0.16; 'received:psf.io': 0.16; 'subject:versus': 0.16; 'wrote:': 0.16; '>>>': 0.20; 'strip': 0.22; 'am,': 0.23; 'header:In-Reply-To:1': 0.24; 'mon,': 0.24; 'header:User-Agent:1': 0.26; 'header:X-Complaints-To:1': 0.26; 'format,': 0.27; 'idea': 0.28; "can't": 0.32; 'subject:) ': 0.32; 'source': 0.33; 'though.': 0.33; "skip:' 20": 0.34; 'to:addr :python-list': 0.36; 'subject:: ': 0.37; 'received:org': 0.37; 'thought': 0.37; 'why': 0.39; 'format': 0.39; 'to:addr:python.org': 0.40; 'show': 0.62; 'believe': 0.66; 'received:109': 0.75; '..........': 0.84; 'becker': 0.84; 'imagine': 0.96 |
| X-Injected-Via-Gmane | http://gmane.org/ |
| X-Gmane-NNTP-Posting-Host | 109.174.168.73 |
| User-Agent | Mozilla/5.0 (Windows NT 6.1; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.1.0 |
| In-Reply-To | <CALwzidko0E8Pq5158_+G1ufWZtFroC9dsaksusF55fSKW5RWfQ@mail.gmail.com> |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.22 |
| 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> |
| X-Mailman-Original-Message-ID | <38b36519-a231-6d76-bc5e-0e6d5f81808d@chamonix.reportlab.co.uk> |
| X-Mailman-Original-References | <7c1af35c-1ac7-96c7-3cba-ab9c8e542d8e@chamonix.reportlab.co.uk> <CALwzidko0E8Pq5158_+G1ufWZtFroC9dsaksusF55fSKW5RWfQ@mail.gmail.com> |
| Xref | csiph.com comp.lang.python:109059 |
Show key headers only | View raw
On 23/05/2016 18:05, Ian Kelly wrote:
> On Mon, May 23, 2016 at 10:39 AM, Robin Becker <robin@reportlab.com> wrote:
.........
>
> If you want to show the float in a less noisy format, you can
> explicitly format it using the 'g' or 'n' presentation type, which
> essentially round to a given precision and strip off trailing zeros:
>
>>>> >>> '{:g}'.format(3*0.2)
> '0.6'
thanks; looking in 2.7 source I believe that the old float.__str__ behaved like
'%.12g' formatting. I can't imagine why people thought this was a 'good' idea
though.
--
Robin Becker
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: str(float) python 3 versus 2.7 Robin Becker <robin@reportlab.com> - 2016-05-24 15:47 +0100
csiph-web