Consider a number abcde. Here, we have 5 digits in that number. Let, say this abcde = n. Then I want a single mathematical function which tells how much digits are there in n.
They could be 3 or 100.
In programming it's easy but it requires more statements. Is this possible to get a single statement. Generally, I not want this for programming.
Asked
Active
Viewed 323 times
-2

Jyrki Lahtonen
- 133,153

umair mughal
- 17
1 Answers
1
If $n$ is a positive integer, the number of decimal digits of $n$ is $\left\lfloor{\log_{10}(n)}\right\rfloor+1$.
Explanation:
Let $n$ be a positive integer. \begin{align*} \text{Then}\;\;&n\;\text{is a $k$-digit number}\\[4pt] \iff\;&10^{k-1}\le n < 10^{k}\\[4pt] \iff\;&k-1\le \log_{10}(n) < k\\[4pt] \iff\;&k-1=\left\lfloor{\log_{10}(n)}\right\rfloor\\[4pt] \iff\;&k=\left\lfloor{\log_{10}(n)}\right\rfloor+1\\[4pt] \end{align*}

quasi
- 58,772
-
Can you send me link to learn how to write equation and formulas here. Is this site use LaTex? – umair mughal Feb 25 '18 at 08:26
-
@umairmughal $\lfloor\log_{10} 95\rfloor +1= \lfloor 1.977\rfloor +1=1+1=2$ – Rohan Shinde Feb 25 '18 at 08:27
-
@umairmughal Refer to https://math.meta.stackexchange.com/questions/5020/mathjax-basic-tutorial-and-quick-reference for Mathjax tutorial – Rohan Shinde Feb 25 '18 at 08:28