How to detect a double's significant digits

Steven Bethard steven.bethard at gmail.com
Thu May 5 14:15:07 EDT 2005


mrstephengross wrote:
> So how can I get the kind of information I want then?
> 
> For example:
> 
> 0.103 --> 3
> 0.0103 --> 4
> 0.00103 --> 5 
> 0.000103 --> 6 
> 0.0000103 --> 7 

Beware that this is probably only relevant if you have your numbers as 
strings, not as floats:

py> 0.103
0.10299999999999999

But, assuming you have your numbers as strings, I would suggest looking 
at str.split() and len().  I'd give you an example, but this sounds 
kinda like a homework assignment.

STeVe



More information about the Python-list mailing list