Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder4.news.weretis.net!rt.uk.eu.org!newsfeed.xs4all.nl!newsfeed4a.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.007 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'that?': 0.05; 'remaining': 0.07; 'string': 0.09; 'thus,': 0.09; 'python': 0.11; '2.7': 0.14; 'floats;': 0.16; 'ignoring': 0.16; 'map:': 0.16; 'precision,': 0.16; 'received:166.84': 0.16; 'received:166.84.1': 0.16; 'received:166.84.1.89': 0.16; 'received:mailbackend.panix.com': 0.16; 'received:panix.com': 0.16; 'roy': 0.16; 'str()': 0.16; 'to:name:python list': 0.16; 'received:10.0.1': 0.19; 'received:166': 0.19; 'parse': 0.24; '---': 0.24; "i've": 0.25; 'point': 0.28; "i'm": 0.30; 'that.': 0.31; 'bunch': 0.31; 'decimal': 0.31; 'values.': 0.31; 'point.': 0.35; 'there': 0.35; 'charset:us-ascii': 0.36; 'subject:?': 0.36; 'received:10.0': 0.36; 'example,': 0.37; 'skip:4 10': 0.37; 'received:10': 0.37; 'to:addr:python-list': 0.38; 'fact': 0.38; 'to:addr:python.org': 0.39; 'how': 0.40; 'problems.': 0.60; 'numbers': 0.61; 'header :Message-Id:1': 0.63; 'map': 0.64; 'between': 0.67; 'smith': 0.68; 'obvious': 0.74; 'email addr:panix.com': 0.84; 'intuit': 0.84 From: Roy Smith Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable Date: Mon, 28 Apr 2014 12:00:23 -0400 Subject: Significant digits in a float? To: Python List Mime-Version: 1.0 (Apple Message framework v1283) X-Mailer: Apple Mail (2.1283) X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 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: 42 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1398700831 news.xs4all.nl 2914 [2001:888:2000:d::a6]:45715 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:70682 I'm using Python 2.7 I have a bunch of floating point values. For example, here's a few = (printed as reprs): 38.0 41.2586 40.75280000000001 49.25 33.795199999999994 36.837199999999996 34.1489 45.5 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 =3D=3D> 0 41.2586 =3D=3D> 4 40.75280000000001 =3D=3D> 4 49.25 =3D=3D> 2 33.795199999999994 =3D=3D> 4 36.837199999999996 =3D=3D> 4 34.1489 =3D=3D> 4 45.5 =3D=3D> 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. The numbers are given to me as Python floats; I have no control over = that. I'm willing to accept that fact that I won't be able to = differentiate between float("38.0") and float("38.0000"). Both of those = map to 1, which is OK for my purposes. --- Roy Smith roy@panix.com