ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

# Creating an animated counter for money

FAQ   •   VIEW ALL Creating an animated counter for money on Mar 30, 2016 at 9:45:59 am

Hi everyone.

I found a great tutorial on here that allows me to type in a figure and the counter will animate up to that amount. The issue is that the last three digits in the counter are separated by a decimal point not by a comma. I need all the separations to be commas as they would be if writing a currency figure.

I've attached to screen shots to show you what it's doing. If you look at the first screen shot you can see that the last three figure are separated by a decimal point not a comma like they are in the other segments. How do I change the expression so that all the separations are commas?  Would very much appreciate someones help on this.

Many thanks in advance,

Peter

```numDecimals = 3 ; commas = true; dollarSign = false; beginCount = -0; endCount = 1000000000000000; dur = 15 ; t = time - inPoint; s = linear (t, 0, dur, beginCount, endCount).toFixed(numDecimals); prefix = ""; if (s == "-"){ 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; } ```

 Return to posts index Re: Creating an animated counter for moneyon Mar 30, 2016 at 10:54:42 am

If what you are trying to achieve is to remove the .000, just change the variable
numDecimals =0

I have simplified the commas section below also.

```numDecimals = 0; commas = true; dollarSign = false; beginCount = -0; endCount = 1000000000000000; dur = 15; t = time - inPoint; s = linear (t, 0, dur, beginCount, endCount).toFixed(numDecimals); prefix = ""; if (s == "-"){ prefix = "-"; s = s.substr(1); } if (commas) s = s.replace(/(\d)(?=(\d{3})+(?!\d))/g, "\$1,"); if(dollarSign) s = "\$" + s; s;```

Declan Smith
http://www.madpanic.tv
After Effects CS6/ FCS3 / Canon XLH1 / Canon 7D / Reason / Cubase

"it's either binary or it's not"

 Return to posts index Re: Creating an animated counter for moneyon Mar 30, 2016 at 11:00:37 am

Hi Declan,

Thank you so much for this, I'll try it out in a bit and let you know how I got on.

Many thanks,

Peter

 Return to posts index Re: Creating an animated counter for moneyon Mar 30, 2016 at 1:10:10 pm

Try this:

```numDecimals = 0; commas = true; dollarSign = false; beginCount = -0; endCount = 1000000000000000; dur = 15; t = time - inPoint; s = linear (t, 0, dur, beginCount, endCount); if (numDecimals) { s = s.toFixed(numDecimals); } else { s = '' + s; } prefix = ""; if (s == "-"){ prefix = "-"; s = s.substr(1); } if (commas) s = s.replace(/(\d)(?=(\d{3})+(?!\d))/g, "\$1,"); if(dollarSign) s = "\$" + s; s;```

Declan Smith
http://www.madpanic.tv
After Effects CS6/ FCS3 / Canon XLH1 / Canon 7D / Reason / Cubase

"it's either binary or it's not"

 Return to posts index Re: Creating an animated counter for moneyon Mar 30, 2016 at 2:04:15 pm

Try this.

```numDecimals = 0; commas = true; dollarSign = false; beginCount = -0; endCount = 1000000000000000; dur = 15; t = time - inPoint; s = linear (t, 0, dur, beginCount, endCount); if (numDecimals) { s = s.toFixed(numDecimals); } else { s = '' + s; } prefix = ""; if (s == "-"){ prefix = "-"; s = s.substr(1); } if (commas) s = s.replace(/(\d)(?=(\d{3})+(?!\d))/g, "\$1,"); if(dollarSign) s = "\$" + s; s;```

Declan Smith
http://www.madpanic.tv
After Effects CS6/ FCS3 / Canon XLH1 / Canon 7D / Reason / Cubase

"it's either binary or it's not"

 Return to posts index