# Finding The Number of Digits

Some problems can ask an answered to find the **number of digits** of an integer or variable. For example, the number 23 has two digits, and the number 1337 has four. But how many digits are in the variable \(x\)? If \(x\) is an integer, and \(x^2\) has more than \(2\) but less than \(4\) digits?

There's not yet enough information to determine exactly what \(x\) is, but a range is ascertainable. If all that's known is that \(x\) is an integer and that \(x^2\) produces an integer that's \(3\) digits long, then \(x\) is on the range \([10,31]\) as \(9^2=81, 10^2 = 100, 31^2=961, and 32^2=1,024\).The wiki will discuss further and more rigorous ways to conduct this analysis.

Note that the numbers with precisely one digit are those integers in the range \( [1,9]\), the numbers with precisely two digits are those integers in the range \( [10, 99]\), and the numbers with precisely three digits are those integers in the range \( [100, 999]\), and so on.

However, determining the number of digits of an extremely large number can be somewhat tricky, and is explored below.

#### Contents

## Large Numbers

A number will have precisely \(j\) digits if and only if it is in the range \(I_j := [10^{j-1}, 10^{j} - 1]\). For instance the number \(5,000,000\) has \(7\) digits, and is in the range \([10^{7-1},10^7-1] = [\text{1,000,000 } , \text{ 9,999,999}]\)

Given an integer \(n\), one can determine \(j\), the number of digits in \(n\), by working with the inequality \[ n\in I_j \implies 10^{j-1} \le n \le 10^j - 1\] Taking logarithms base 10 gives \[j-1 \le \log_{10} (n) < j\] It follows that \(j-1 = \lfloor \log_{10} (n) \rfloor\), where \(\lfloor x \rfloor\) is the floor function, denoting the greatest integer less than or equal to \(x\) (for instance\(\lfloor \pi \rfloor = 3\)). Thus, \(j = \lfloor \log_{10} (n) \rfloor + 1\).

For any natural number \(n\), the number of digits in \(n\) is \(\lfloor \log_{10} (n) \rfloor + 1\).

For instance, for the example \(5,000,000\), \(\lfloor \log_{10} (5000000) \rfloor = 6\) so \( \lfloor \log_{10} (5000000) \rfloor +1 = 7\) which is the number of digits in \(5,000,000\)

## Examples

How many digits does \(100!\) have?

We must compute \(\lfloor \log_{10} (100!) \rfloor + 1\). Stirling's Formula says that for any positive integer \(n\) , we have the bounds, \( \sqrt{2\pi}\ n^{n+1/2}e^{-n} \le n! \le e\ n^{n+1/2}e^{-n}. \) So for \(\lfloor \log_{10} (100!) \rfloor + 1\): \[\log_{10} (\sqrt{2\pi})) + \left(n + \frac{1}{2} \right) \log_{10} (n) -\frac{n}{\ln(10)} \le \log_{10} (n!) \le 1 + \left(n + \frac{1}{2} \right) \log_{10} (n) -\frac{n}{\ln(10)} \] Using a calculator with \(n=100\), this implies the numerical inequality \(101.4 \le \log_{10}(100!) \le 102\). It follows \(\lfloor \log_{10} (100!) \rfloor = 101\), hence \(100!\) has 102 digits.

**Cite as:**Finding The Number of Digits.

*Brilliant.org*. Retrieved from https://brilliant.org/wiki/finding-digits-of-a-number/