0

examples:

0.28 --> 2

0.1234 --> 4

0.01345000 --> 5

My answer:

len(str(k)[str(k).index('.')+1:])

It works but it is also super ugly. Anything more pythonic?

Dan Mahowny
  • 163
  • 1
  • 10
  • 1
    I would be very careful about floats and any guarantee of number of decimals, e.g. `str(0.1+0.2) == '0.30000000000000004'` you might have expected only `1` but your function returns `17`. Use [`Decimal`](https://docs.python.org/3/library/decimal.html?highlight=decimal#decimal-objects) if you want any certainty. – AChampion Jul 30 '18 at 13:48
  • for completeness, in order to first drop the zeros on the right side of the decimal object, we must use the normalize() method first. – Dan Mahowny Jul 30 '18 at 13:56

0 Answers0