MathGroup Archive 2011

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: count zeros in a number


dimitris wrote:

I would convert to a string and use a regular expression:

trailingZeros[n_] :=
 StringLength@StringCases[ToString[n], RegularExpression["0+$"]]

trailingZeros[24^24 55^55]
Out={55}

trailingZeros[10000!]
Out={2499}

> Hello.
>
> Consider e.g. the number 24^24*55^55.
> This number ends with exactly 55 zeros as the following demonstrate
>
> In[201]:= Mod[24^24*55^55, 10^55]
> Mod[24^24*55^55, 10^56]
>
> Out[201]= 0
> Out[202]= 20000000000000000000000000000000000000000000000000000000
>
>
> What I want now is a way to count the zeros that a number ends without
> knowing in advance this number of zeros like in the above example.
>
> Thanks in advance.
> Dimitris
>

-- 
_________________________________________________________________
Peter Breitfeld, Bad Saulgau, Germany -- http://www.pBreitfeld.de



  • Prev by Date: workaround for GraphPlot not accepting node list?
  • Next by Date: Re: count zeros in a number
  • Previous by thread: Re: count zeros in a number
  • Next by thread: Re: count zeros in a number