Given a positive number n find the number of trailing zeroes [closed]

I want to find the formula for calculating the number of trailing zeroes in a given number.

There are certain points that must be factored in the calculation of the number of trailing zeroes. They are:

1. Only trailing zeroes before the decimal point are considered in the calculation.
2. In case there are no trailing zeroes in the number then the count is 0.
3. The numbers are positive and will range from 1 to n

Examples:

1. n = 53000 --> number of zeroes are 3
2. n = 9000.201 --> number of zeroes are 3
3. n = 41333.00 --> number of zeroes is 0
4. n = 200.00 --> number of zeroes are 2

To factor in the decimal scenario, I can do an integer division and then find the number of zeroes. But the issue is what is a good mathematical formula to calculate it directly.

EDIT: I wanted to avoid any iterative approach to find the number of trailing zeroes.

closed as unclear what you're asking by 5xum, Matthew Daly, Shailesh, José Carlos Santos, Daniele TampieriSep 15 at 6:47

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

• Any thoughts? Isn't it just the order to which $10$ divides $\lfloor n\rfloor$? – lulu Sep 11 at 11:13
• What do you mean by "I want to find" them? Do you need a formula for them? A computer program? – 5xum Sep 11 at 11:20
• You are clearly able to find the number of trailing zeros if you write the numbers down. What information are you given as inputs to the problem, and what tools do you have available (eg pen and paper, or do you want some algorithm or formula, and if so in what language) – Mark Bennet Sep 11 at 11:25
• Hi @5xum I have updated the question. I need a proper formula/transformation which returns the number of zeroes. – Mahendra Singh Sep 11 at 11:25
• Let $f$ be a function that, to every $n \in \mathbb{N}$, assigns the number of trailing zeros for $n$. Then $f(n)$ is the maximum number $k$ such that $10^k$ divides $n$. You can replace $10$ by any other number to work the same function for other bases – David Sep 11 at 11:31

Let n be your given number then the output function you need is

$$f(n)=max\left \{i\in \mathbb{N}\;\; |\;\ \left \lfloor n \right \rfloor_{GIF} \;modulo\; 10^i = 0 \right \}$$

Or

$$f(n)=max\left \{i\in \mathbb{N}\;\; |\;\ \frac{\left \lfloor n \right \rfloor_{GIF}}{10^i}=\left \lfloor \frac{n}{10^i} \right \rfloor_{GIF}\right \}$$

Let $$f$$ be a function that, to every $$n \in \mathbb{N}$$, assigns the number of trailing zeros for $$n$$. Then $$f(n)$$ is the maximum number $$k$$ such that $$10^k$$ divides $$n$$.So:

$$f(n):= \max \{k \in \mathbb{N} : 10^k |n\}$$

You can replace $$10$$ by any other number to work the same function for other counting bases

• Is there a transformation which can give the results similar to counting number of digits using logarithmic. For ex: number of digits = floor(log10(2000)) + 1 – Mahendra Singh Sep 11 at 11:44
• What if n is not a natural number? – KNilesh Sep 11 at 11:46
• @KumarNilesh If we are defining our function for reals rather than integers, then the number of trailing zeros is either $0$, as in $\frac{1}{9}$ or infinite, as in $1=1.0000000000......$ – David Sep 11 at 13:32
• @David I didn't mean that, If you'll look at his examples there is a case: n = 9000.201 --> number of zeroes are 3. I am talking about this case. – KNilesh Sep 11 at 13:58
• @KumarNilesh Then it's easy. Just round the numbers down! – David Sep 11 at 13:59