Is there a way in Python to count the significant figures in a double/float/etc? I'm not seeing an easy way to do this, but I'd expect it to be in the library.
Thanks in advance.
You may be interested in an arbitrary precision floating point library such as this one:
http://code.google.com/p/mpmath/
I found a solution to this post in another question:
Python counting significant digits
The idea here is that you pass the float as a String to the methods, and then the method uses regular expressions to count the number of significant digits by splitting strings where "e"
is (for float string in scientific format) and where the dot is (for normal float strings).
It seems to work well up to 8 significant digits, but the behavior is not guaranteed after the 9th.
Still, I believe this is better than the
"Significant digits are just not that big a deal and get little support in computer languages"
response. It may not be easy, but you can definitely do it, even if not perfectly.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With