-
Creating an animated counter for money
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[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;
}


