FORUMS: list search recent posts

# changing the number of digits in Dan's counter expression

FAQ   •   VIEW ALL
 changing the number of digits in Dan's counter expression on Nov 13, 2010 at 7:56:34 am

Hi,

I'm loving Dan's counter expression.

Anyone able to tell me how to modify it to display a fixed number of digits, so 1 would be represented as 0000001 for example?

Thanks for the help.

```numDecimals = 2; commas = true; dollarSign = true; beginCount = -1999; endCount = 1999; dur = 4; t = time - inPoint; s = linear (t, 0, dur, beginCount, endCount).toFixed(numDecimals); prefix = ""; if (s[0] == "-"){ prefix = "-"; s = s.substr(1); } if(dollarSign) prefix += "\$"; if (commas){ decimals = ""; if (numDecimals > 0){ decimals = s.substr(-(numDecimals + 1)); s = s.substr(0,s.length - (numDecimals + 1)); } outStr = s.substr(-s.length, (s.length-1)%3 +1); for (i = Math.floor((s.length-1)/3); i > 0; i--){ outStr += "," + s.substr(-i*3,3); } prefix + outStr + decimals; }else{ prefix + s; }```

 Re: changing the number of digits in Dan's counter expressionon Nov 13, 2010 at 8:33:43 pm

This is the basic idea:

n = 1; // your number
numDigits = 7;
s = "" + n
while (s.length < numDigits) s = "0" + s;
s