Significant figures calculation
Jerry Hill
malaclypse2 at gmail.com
Fri Jun 24 16:58:56 EDT 2011
On Fri, Jun 24, 2011 at 4:46 PM, Steven D'Aprano
<steve+comp.lang.python at pearwood.info> wrote:
> Really? It works for me.
>
>>>> import decimal
>>>> D = decimal.Decimal
>>>> decimal.getcontext().prec = 2
>>>>
>>>> D('32.01') + D('5.325') + D('12')
> Decimal('49')
I'm curious. Is there a way to get the number of significant digits
for a particular Decimal instance? I spent a few minutes browsing
through the docs, and didn't see anything obvious. I was thinking
about setting the precision dynamically within a function, based on
the significance of the inputs.
--
Jerry
More information about the Python-list
mailing list