# The number of digits in n! (Part 3)

The following graph shows the number of digits in $n!$ as a function of $n$. When I was in school, I stared at this graph for weeks, if not months, trying to figure out an equation that would fit these points. And I never could figure it out.

When I took calculus in college, I distinctly remember getting up the nerve to ask my professor, the great L.Craig Evans (now at UC Berkeley), if he knew how to solve this problem. To my great consternation, he immediately wrote down what I now realize to be the right answer, using Stirling’s approximation: $\ln n! \approx \left(n + \displaystyle \frac{1}{2} \right) \ln n - n + \frac{1}{2} \ln (2\pi)$

While I now know that this was the way to go about solving this problem, I didn’t appreciate how this formula could help me at the time. I only saw the $n!$ on the left-hand side and did not see the immediate connection between this formula and the number of digits in $n!$.

But now I know better.

For starters, the number of base-10 digits in a number $n$ is always the next integer greater that $\log_{10} n$. For example, $\log_{10} 2000 \approx 3.301$, and the next integer larger than $3.301$ is 4. Unsurprisingly, the number $2000$ has 4 digits.

Second, the change of base formula for logarithms gives $\log_{10} n! = \displaystyle \frac{\ln n!}{\ln 10}$

Therefore, the number of digits in $n!$ will be about $\displaystyle \frac{\left(n + \displaystyle \frac{1}{2} \right) \ln n - n + \frac{1}{2} \ln (2\pi)}{\ln 10}$

The graph below shows just how accurate this approximation really is. The solid curve is the approximation; the dots are the values of $\log_{10} n!$. (In other words, this series of dots are only slightly different than the dots above, which have integers as coordinates.) Not bad at all… the error in the approximation is smaller than the size of the dots in this picture. ## One thought on “The number of digits in n! (Part 3)”

This site uses Akismet to reduce spam. Learn how your comment data is processed.