How to detect a double's significant digits

Charles Krug cdkrug at worldnet.att.net
Thu May 5 14:42:17 EDT 2005


On 5 May 2005 10:37:00 -0700, mrstephengross <mrstephengross at hotmail.com> wrote:
> Hi all... How can I find out the number of significant digits (to the
> right of the decimal place, that is) in a double? At least, I *think*
> that's what I'm asking for. For instance:
> 
> 0.103 --> 3
> 0.0103 --> 4
> 0.00103 --> 5
> 0.000103 --> 6
> 0.0000103 --> 7
> 
> Thanks in advance!
> --Steve (mrstephengross at hotmail.com)
> 

I would say that each of these examples has three signficant figures.
Each of them can be expressed as:

1.03e+n

For any integer n.

The fact that you've only shown the cases where n \in {-1, -2, -3, -4,
-5 . . } doesn't change the generality of the answer.




More information about the Python-list mailing list