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:
  • n (int/float/list/array) – number or list of numbers

  • args (list) – additional numbers

  • count_minus (bool) – whether to count the minus sign as a digit

  • count_decimal (bool) – whether to count the decimal point as a digit

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.