# Calculating the Number of Digits in x

• soandos
In summary, there are multiple ways to estimate or calculate the number of digits in x!, including using Stirling's formula, the series formula, or calculating the logarithms of the terms. It ultimately depends on the size of n and the desired level of precision. Some software, such as Mathematica, may have functions to help with this calculation.
soandos
is there a way to determine (does not need to be exact) the number of digits in x! ?

sorry if this is kind of pointless

For large n, use Stirling's formula:

n! ~ (2[pi]n)1/2 (n/e)n

soandos said:
is there a way to determine (does not need to be exact) the number of digits in x! ?

O(x log x).

To be more precise, x log x - x log e + O(log x), where the base of the logarithms is the base you want to express the number.

Don't forget to then apply

$$D = 1 + \lfloor \log_{10} \lfloor n! \rfloor \rfloor$$

after that for the number of digits.

Gib Z said:
Don't forget to then apply

$$D = 1 + \lfloor \log_{10} \lfloor n! \rfloor \rfloor$$

after that for the number of digits.

If $$n!$$ is hard to calculate, the series

$$D = 1 + \lfloor \sum^n_{i=1} \log_{10}i \rfloor$$

should be easier to calculate - for integer $$n$$.

Jarle said:
If $$n!$$ is hard to calculate, the series

$$D = 1 + \lfloor \sum^n_{i=1} \log_{10}i \rfloor$$

should be easier to calculate - for integer $$n$$.

Depends how large n is. If it's quite large, calculating logs for each term up to it may not be easier than using Stirlings Formula which simplifies into something that doesn't look that bad after a log anyway. But that definitely is a good idea =]

Anyone know of a way to get an answer just to a certain precision in mathematica?
I do no mean truncating the answer, but more the way a person would, so for example,
1/"insert incredibly long hard to calculate mess here" as zero, or instead of getting the inside of a natural log to hundreds of decimal points, just get it to 10 or so.
is there a way to do that?

## 1. How do I calculate the number of digits in a given number?

To calculate the number of digits in a given number, you can use the logarithm function. The formula for calculating the number of digits in a number x is log10(x) + 1. This will give you the total number of digits, including any decimal places.

## 2. What if the number has leading or trailing zeros?

If the number has leading or trailing zeros, you can use the same formula as mentioned above, but exclude the zeros from the calculation. For example, if the number is 00234, you would only count the digits 2, 3, and 4, giving you a total of 3 digits.

## 3. Is there a way to calculate the number of digits without using logarithms?

Yes, you can also calculate the number of digits in a number by converting it to a string and counting the number of characters. However, this method may not work for very large numbers or numbers with decimals.

## 4. Can I calculate the number of digits in a non-integer number?

Yes, you can use the same formula for calculating the number of digits in a non-integer number. The result will include the digits after the decimal point as well.

## 5. How can I calculate the number of digits in a negative number?

To calculate the number of digits in a negative number, you can first remove the negative sign and then use the same formula as mentioned above. The result will be the same as the number of digits in the positive version of the number.

• General Math
Replies
3
Views
1K
• General Math
Replies
11
Views
1K
• General Math
Replies
4
Views
621
• General Math
Replies
7
Views
1K
• General Math
Replies
1
Views
631
• General Math
Replies
12
Views
2K
• General Math
Replies
20
Views
2K
• General Math
Replies
2
Views
909
• General Math
Replies
4
Views
2K
• General Math
Replies
1
Views
1K