Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!news.albasani.net!newsfeed.straub-nv.de!newsfeed1.swip.net!npeer01.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!spln!extra.newsguy.com!newsp.newsguy.com!not-for-mail From: Chris Torek Newsgroups: comp.lang.python Subject: Re: Significant figures calculation Date: 25 Jun 2011 19:04:52 GMT Organization: None of the Above Lines: 26 Message-ID: References: <10b8388e-76fc-4a93-aeff-676cdb3d1d12@5g2000yqb.googlegroups.com> <4e04f793$0$29975$c3e8da3$5496439d@news.astraweb.com> NNTP-Posting-Host: p5337b1c1e6bde602a95fda2149f0e9cf7d5677efd54f9d34.newsdawg.com X-Newsreader: trn 4.0-test76 (Apr 2, 2001) Originator: torek@elf.torek.net (Chris Torek) Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:8451 In article Jerry Hill wrote: >I'm curious. Is there a way to get the number of significant digits >for a particular Decimal instance? Yes: def sigdig(x): "return the number of significant digits in x" return len(x.as_tuple()[1]) import decimal D = decimal.Decimal for x in ( '1', '1.00', '1.23400e-8', '0.003' ): print 'sigdig(%s): %d' % (x, sigdig(D(x))) -- In-Real-Life: Chris Torek, Wind River Systems Intel require I note that my opinions are not those of WRS or Intel Salt Lake City, UT, USA (40°39.22'N, 111°50.29'W) +1 801 277 2603 email: gmail (figure it out) http://web.torek.net/torek/index.html