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 have, if has more than 2 but less than 4 digits?
There's not yet enough information to determine exactly what is, but a range is ascertainable. If all that's known is that is an integer and that produces an integer that's digits long, then is on the range as and .
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 , the numbers with precisely two digits are those integers in the range , and the numbers with precisely three digits are those integers in the range , 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.
A number will have precisely digits if and only if it is in the range . For instance, the number has digits and is in the range
Given an integer , one can determine , the number of digits in , by working with the inequality
Taking the base 10 logarithm gives
so where is the floor function, denoting the greatest integer less than or equal to . Thus, .
For any positive integer , the number of digits in is .
For example, take , then meaning that we expect this number to have digits, which in fact it does.
How many digits does have?
Using Stirling's formula we can get the number of digits of as follows: