Is there an easy way or integrated function to find out the decimal places of a floating point number?
The number is parsed from a string, so one way is to count the digits after the '.' sign, but that looks quite clumsy to me. Is there a possibility to get the information needed out of a float
or Decimal
object?
SOLUTION (one of them, of course :) )
I chose to use the python decimal.Decimal class to help me with my problem:
e = abs(Decimal(string_value).as_tuple().exponent)
NOTE: this only works when the parameter from which the Decimal is constructed is a string and not a float (which would lead to floating point inaccuracies).
Thanks a lot for all other contributions.
Question&Answers:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…