Relevant For...

Some problems ask you 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 does an integer \(x\) have, if \(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. The two digit numbers are shown below:

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}].\)

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

For example, take \(n = 5,000,000\), so \(\left\lfloor \log_{10} (5000000) \right\rfloor = 6,\) meaning that we expect this number to have \( \left\lfloor \log_{10} (5000000) \right\rfloor +1 = 7\) digits, which in fact it does.

Examples

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

Using Stirling's formula \(n! \approx \sqrt{2\pi n}\left(\frac ne \right)^n,\) we can get the number of digits of \(100!\) as follows: