numdigits#
- numdigits(n, *args, count_minus=False, count_decimal=False)[source]#
Count the number of digits in a number (or list of numbers).
Useful for e.g. knowing how long a string needs to be to fit a given number.
If a number is less than 1, return the number of digits until the decimal place.
Reference: https://stackoverflow.com/questions/22656345/how-to-count-the-number-of-digits-in-python
- Parameters:
Examples:
sc.numdigits(12345) # Returns 5 sc.numdigits(12345.5) # Returns 5 sc.numdigits(0) # Returns 1 sc.numdigits(-12345) # Returns 5 sc.numdigits(-12345, count_minus=True) # Returns 6 sc.numdigits(12, 123, 12345) # Returns [2, 3, 5] sc.numdigits(0.01) # Returns -2 sc.numdigits(0.01, count_decimal=True) # Returns -4
New in version 2.0.0.