Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am trying to figure out the mathematical relation between a number and the number of digits that number has.
For e.g. Relation between 0, 1, 2...9 and 1,

     or between 10, 11, 12...99 and 2, 

     or between 100, 101, 102...999 and 3, 

     or between 1000, 1001,...5000, 5001, ...9999 and 4.

So given a number having 'n' digits whose value is 'x', I want to express it as

n = f(x)

I could figure out the following:

x = ∑(10^i * xi)  where i=1 to n.  Where xi is the digit at position i.

So x = x1 + 10*x2 + 10^2*x3 + ... + 10^n*xn

Where x1, x2, x3 etc. are digits at unit, tenth, hundredth positions respectively.

I am surely missing something here. Any help is appreciated



share|cite|improve this question
up vote 3 down vote accepted

Is this what you want?

  • If a number $n$ has $k$ digits, then $10^{k-1} \le n < 10^{k}$.

  • If a number $n$ has $k$ digits, then $k = \lfloor\log n\rfloor + 1$ where $\log$ is to base $10$.

Replace $10$ with $b$ if you're using a different base $b$.

share|cite|improve this answer

You are not missing anything.

A representation of a number $x$ in base $d$ is the (unique) sum $x=\sum_{i=0}^n a_id^i$ with $0\le a_i<d$ for all $0\le i\le n$ (the $a_i$'s are the digits in that base).

I'm not sure what else you want to find.

share|cite|improve this answer
Well, it would probably be worth mentioning logarithms and the formula $f(x) = \lfloor \log_{10}(x) \rfloor + 1$ for the number of digits of $x$. – t.b. Jun 6 '11 at 16:46
Yes. Kudos for ShreevastaR. – Gadi A Jun 6 '11 at 16:53

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.