Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #70683
| Path | csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.datemas.de!rt.uk.eu.org!newsfeed.xs4all.nl!newsfeed2a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| 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.003 |
| X-Spam-Evidence | '*H*': 0.99; '*S*': 0.00; 'that?': 0.05; 'remaining': 0.07; 'string': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'thus,': 0.09; 'way:': 0.09; 'ignoring': 0.16; 'map:': 0.16; 'precision,': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'roy': 0.16; 'str()': 0.16; 'wrote:': 0.18; 'header:User-Agent:1': 0.23; 'parse': 0.24; 'skip:l 30': 0.24; "i've": 0.25; 'header:X-Complaints-To:1': 0.27; 'header:In-Reply-To:1': 0.27; 'point': 0.28; 'decimal': 0.31; 'point.': 0.35; 'there': 0.35; 'subject:?': 0.36; 'skip:4 10': 0.37; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'how': 0.40; 'problems.': 0.60; 'numbers': 0.61; 'between': 0.67; 'smith': 0.68; 'obvious': 0.74; 'intuit': 0.84; 'technique.': 0.84 |
| X-Injected-Via-Gmane | http://gmane.org/ |
| To | python-list@python.org |
| From | Ned Batchelder <ned@nedbatchelder.com> |
| Subject | Re: Significant digits in a float? |
| Date | Mon, 28 Apr 2014 12:07:14 -0400 |
| References | <B654EA7E-35C7-4A78-A673-4CAD0C23B5C0@panix.com> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=ISO-8859-1; format=flowed |
| Content-Transfer-Encoding | 7bit |
| X-Gmane-NNTP-Posting-Host | 18.189.27.191 |
| User-Agent | Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:24.0) Gecko/20100101 Thunderbird/24.4.0 |
| In-Reply-To | <B654EA7E-35C7-4A78-A673-4CAD0C23B5C0@panix.com> |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.15 |
| 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> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.9550.1398701251.18130.python-list@python.org> (permalink) |
| Lines | 21 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1398701251 news.xs4all.nl 2931 [2001:888:2000:d::a6]:48602 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:70683 |
Show key headers only | View raw
On 4/28/14 12:00 PM, Roy Smith wrote:
> Fundamentally, these numbers have between 0 and 4 decimal digits of precision, and I want to be able to intuit how many each has, ignoring the obvious floating point roundoff problems. Thus, I want to map:
>
> 38.0 ==> 0
> 41.2586 ==> 4
> 40.75280000000001 ==> 4
> 49.25 ==> 2
> 33.795199999999994 ==> 4
> 36.837199999999996 ==> 4
> 34.1489 ==> 4
> 45.5 ==> 1
>
> Is there any clean way to do that? The best I've come up with so far is to str() them and parse the remaining string to see how many digits it put after the decimal point.
That sounds like a pretty clean way: len(str(num).partition(".")[2]),
though it also sounds like you understand all of the inaccuracies in
that technique.
--
Ned Batchelder, http://nedbatchelder.com
Back to comp.lang.python | Previous | Next — Next in thread | Find similar | Unroll thread
Re: Significant digits in a float? Ned Batchelder <ned@nedbatchelder.com> - 2014-04-28 12:07 -0400
Re: Significant digits in a float? Roy Smith <roy@panix.com> - 2014-04-28 11:39 -0700
Re: Significant digits in a float? Ned Batchelder <ned@nedbatchelder.com> - 2014-04-28 15:00 -0400
csiph-web