For the coding exercises I'm working on, I'm trying to compare two numbers and choose the one with the most significant numbers.
For example: compare 2.37e+07and 2.38279e+07, select 2.38279e+07, because it has more significant numbers.
I do not know how to implement this in Python. I counted counting the length of each number using len(str(NUMBER)), but this method returns “10” for both numbers above, because it does not distinguish between zero and nonzero digits.
How can I compare the number of significant digits in Python?
source
share