ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

# number counter

FAQ   •   VIEW ALL number counter by rubefinkon Oct 16, 2007 at 10:18:22 pm

I'm trying to create a simple looking number counter. It has to go from zero to 130,000 then back to 1,000. I tried using the number Effect but it taps out at 30,000 for some reason and I need to go higher. Does anyone have any ideas? If the answer is using expressions well I know very little of that so you'de have to break it down for me. I saw the odometer tutorial but this job doesn't need anything that fancy. Just numbers changing in sequential order would be great. Thanks.

- rube Re: number counteron Oct 17, 2007 at 12:09:35 am

Here's a Dan expression that goes on Source Text, link below.

1) Put any letter on the screen where you want it with the Text Tool, the font you want and the size you want for your counter.

Add the following expression for Source Text (Copy the expression, Alt-Click the Source Text Stopwatch, Paste, click outside the box):

numDecimals = 0;
commas = true;
dollarSign = false;
beginCount = 0;
endCount = 130000;
dur = 4;

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;
}

This will count from zero to 130,000 in four seconds (dur, line 6 in code above).

To go from 130,000 back to 1000, first trim that first text layer (Alt }) then I'd duplicate the Text layer, slide it back until it takes over where the first text layer stops, then change the expression, line 4 to;

beginCount = 130,000;

and line 5 to:

endCount = 1000;

That should do it. Dan's expression lives here for a complete explanation:

http://www.motionscript.com/design-guide/counter.html Re: number counteron Mar 27, 2010 at 6:48:28 pm

Thank you thank you, I have been trying to figure out how to do this and with no suggests until now, it works beautifully . Thanks so much.

Troy

Troy Ruff Re: number counteron Jun 29, 2012 at 8:22:24 pm

Helped me a lot!
I made some modifications to this expression, to make it the most common AE FX.
As an example, add a "Slider Control" on the key frame.
example:

effect ("Slider Control") ("Slider") added in place of the value of "beginCount" and "endCount"

beginCount = effect ("Slider Control") ("Slider");
endCount = effect ("Slider Control") ("Slider");

So you have control over the length "dur"
What you can put as "0"

For only with such modifications you already have the control when it starts and ends when through the key frame. Re: number counteron Mar 24, 2014 at 7:06:11 pm

I'm working on a project and I used this code and it works great, thank you for that!

I'm trying to include text at the end of the number, for example, I have the the counter ending at \$4.2 but I wanted to add the "M" after the number 2, how can I do that. Re: number counteron Mar 24, 2014 at 7:36:01 pm

You should be able to change the last 4 lines to something like this:

prefix + outStr + decimals + "M";
}else{
prefix + s + "M";
}

Dan Re: number counteron May 12, 2017 at 1:25:53 am

Hi Dan,
Is there any way to mix different font size and color? It seems they do not carry over from the original text.
Thanks,
Jim Re: number counteron May 12, 2017 at 3:36:25 am

Unfortunately, everything gets the same formatting as the first character. You could a Fill Color Animator, but that doesn't help you with font size. If it's important, you'll probably need to use separate text layers and use sourceRectAtTime() to position the pieces horizontally.

Dan Re: number counteron Apr 22, 2016 at 6:53:13 am