How to detect a double's significant digits

Fredrik Lundh fredrik at pythonware.com
Thu May 5 15:30:13 EDT 2005


"mrstephengross" wrote:

> >But, assuming you have your numbers as strings, I would suggest
> looking
> at str.split() and len().
>
> Well, the numbers are in fact stored as numbers, so string processing
> won't work.

if they're not strings, your question is meaningless.  as others have
pointed out, the exact internal representation for 0.103 is more like
0.10299999999999999433786257441170164383947849273681640625
which has a lot more than 3 digits...

> >I'd give you an example, but this sounds kinda like a homework
> assignment.
>
> The task may sound like it comes from class, but I can assure you that
> I am indeed a professional developer.

well professional or not, you clearly need to refresh your floating point
skills.  I suggest reading the following documents before proceeding:

    http://docs.python.org/tut/node16.html
    http://www.lahey.com/float.htm

</F>






More information about the Python-list mailing list