How to detect a double's significant digits

phil phillip.watts at anvilcom.com
Thu May 5 14:04:21 EDT 2005


fl = 1.0002
x = str(fl)
pos = x.find('.')
print len( x[pos+1:] )
 >>> 4

mrstephengross 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)
> 
> 






More information about the Python-list mailing list