ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

# Expression Count Up Percentage

FAQ   •   VIEW ALL
 Expression Count Up Percentage on Sep 2, 2009 at 10:41:23 pm

I would like to know if anyone knows of an expression that will let you count up a number with a percentage sign. For example I would like the initial number to read 0% and count up to 100%. I have tried to alter an expression I have that allows a dollar sign and I get an error. Any info would be appreciated.

 Re: Expression Count Up Percentageon Sep 3, 2009 at 12:09:43 am

A text expression like this should work:

beginCount = 0;
stopCount = 100;

beginTime = 0; // start counting at time = 0
countDur = 4; // count for 4 seconds

"" + Math.round(linear(time,beginTime,beginTime + countDur,beginCount,stopCount)) + "%"

Dan

 Re: Expression Count Up Percentageon Apr 27, 2010 at 10:55:50 pm

Thank you. This expression worked perfectly.

 Re: Expression Count Up Percentageon Sep 14, 2010 at 4:36:49 pm

I'm going to use this expression again, but I need to add a decimal. Do you have an expression for that?

I need to go from 12.3% to 10.1%

 Re: Expression Count Up Percentageon Sep 14, 2010 at 5:07:13 pm

Try this:

beginCount = 123;
stopCount = 101;

beginTime = 0; // start counting at time = 0
countDur = 4; // count for 4 seconds
count = linear(time,beginTime,beginTime+countDur,beginCount,stopCount)/10;
count.toFixed(1) + "%"

Dan

 Re: Expression Count Up Percentageon Jun 25, 2013 at 9:51:08 pm

Hi there, how could I make this do the opposite and make it count backwards? I tried playing with some of the text but was way off :)

(I already got it to work by just making it a pre-comp and then reversing the time for the purposes of getting what I need done fast, but I was just curious what the code would look like :) )

Thanks!

 Re: Expression Count Up Percentageon Jun 25, 2013 at 10:19:34 pm

If you want it to reverse the count direction, just change this:

beginCount = 123;
stopCount = 101;

to this:

beginCount = 101;
stopCount = 123;

Is that what you mean?

Dan

 Re: Expression Count Up Percentageon Jun 25, 2013 at 10:24:06 pm

I tired that and it wouldn't work, did I type something wrong?

beginCount = 55;
stopCount = 0;
beginTime = 55; // start counting at time = 0
countDur = 1; // count for 4 seconds
"" + Math.round(linear(time,beginTime,beginTime + countDur,beginCount,stopCount)) + "%"

 Re: Expression Count Up Percentageon Jun 25, 2013 at 11:43:57 pm

You have it set up to start counting at 55 seconds into the comp, and to count down from 55 to 0 over a 1-second duration. I'm guessing maybe you wanted it to start counting at an earlier time. Just set beginTime to whatever that is. If that's not the issue, please explain what it is that you want it to do.

Dan

 Re: Expression Count Up Percentageon Oct 8, 2012 at 2:34:22 pm

i was have same problem here too but as i Google for solution i saw this post under the search result and it just answer my question thanks for this post.

```beginCount = 0; stopCount = 100; beginTime = 0; // start counting at time = 0 countDur = 4; // count for 4 seconds "" + Math.round(linear(time,beginTime,beginTime + countDur,beginCount,stopCount)) + "%"```

 Re: Expression Count Up Percentageon Dec 24, 2012 at 10:18:27 am

useful expression .. but how can I ease-in or ease-out the %tage countdown/countup?

`beginCount = 0; stopCount = 100; beginTime = 0; // start counting at time = 0 countDur = 4; // count for 4 seconds "" + Math.round(linear(time,beginTime,beginTime + countDur,beginCount,stopCount)) + "%"`

 Re: Expression Count Up Percentageon Dec 24, 2012 at 5:56:32 pm

Try changing "linear" to "ease" or "easeIn" or "easeOut".

Dan

 Re: Expression Count Up Percentageon Feb 14, 2013 at 10:30:39 am

thanks dan , and how if i want give symbol in front of number ?

 Re: Expression Count Up Percentageon Feb 14, 2013 at 6:35:28 pm

Just add it in front like this:

"\$" + count

Dan

 Re: Expression Count Up Percentageby Spiroon Nov 5, 2013 at 3:54:26 pm

I can't figure out how to start with something like "\$0000" on screen, and have it count up from there. All the expressions I've found start with "\$0." I want to initially start with four zeros.

 Re: Expression Count Up Percentageon Nov 5, 2013 at 7:44:45 pm

Try this:

beginCount = 0;
stopCount = 100;

beginTime = 0; // start counting at time = 0
countDur = 4; // count for 4 seconds

count = linear(time,beginTime,beginTime+countDur,beginCount,stopCount);
s = "" + Math.floor(count);
while (s.length < 4) s = "0"+s;
"\$"+s

Dan

 Re: Expression Count Up Percentageon Mar 31, 2016 at 12:23:30 am

Hey Dan, I know this is an old post. Just wanted to ask... Where did you learn all that? I've been an independent producer since 3 years ago and AE is still one bigger weaknes. Greetins and thanks in advance.

 Re: Expression Count Up Percentageon Mar 31, 2016 at 12:54:25 am

I just jumped in when AE got expressions. I hadn't really seen JavaScript before that, so I'm still learning as I go...

Dan

 Re: Expression Count Up Percentageon Apr 22, 2016 at 6:35:14 am

Hi Dan
Just wanted to say Thanks for spreading your knowledge on Expressions. I learned a lot from reading your Posts and Articles over the years, and today I love using expressions thanks to you.
I've created a Counter Preset that will save everyone the headache of creating counter Animations:
http://www.vdodna.com/products/counter-preset/

I'll Send you a gift copy through your site.
Thanks
Liran

 Re: Expression Count Up Percentageon Apr 22, 2016 at 6:29:14 pm

Hi Dan,

Your expressions are really good and could use your expertise on figuring something similar to this one out.

I have two layers. Layer 1's opacity goes from 0-100% (this percentage is controlled by the progress of another layers effect that I have already linked it to). I want layer 2's opacity to go from 0-100% as well but only start when Layer 1 is at 87%. How would I do that and end at 100% when Layer 1 reaches 100%?

Thanks,

Josh

 Re: Expression Count Up Percentageon Apr 22, 2016 at 6:45:54 pm

This should work:
v1 = thisComp.layer("layer 1").transform.opacity;
linear (v1,87,100,0,100)

Dan

 Re: Expression Count Up Percentageon Apr 22, 2016 at 6:54:13 pm

Hi Dan,

Worked perfect. Thank you. So I can learn more about the coding structure for AE can you explain what each number in this string represents (v1, 87, 100, 0, 100)?

Does:
v1 rep the opacity of layer 1 at any given time
87 target start value of layer 2
100 end value of layer ?
0,100 change opacity of layer 2 from 0-100

Thanks,

Josh

 Re: Expression Count Up Percentageon Apr 22, 2016 at 7:08:33 pmLast Edited By Dan Ebberts on Apr 22, 2016 at 7:09:15 pm

>v1 rep the opacity of layer 1 at any given time

Yes.

The second line of the expression essentially says "as the opacity of layer 1 varies from 87 to 100, vary the opacity of this layer from 0 to 100". It's in the AE help manual under Interpolation methods.

Dan

 Re: Expression Count Up Percentageon Apr 22, 2016 at 7:11:39 pm

Thank you again. I will look this up.

Best,

Josh

 Re: Expression Count Up Percentageon Jan 4, 2017 at 4:57:02 pm

Thanks for all the good advice so far. But how is it possible to make the percentage "slider controllable"?

Basically what I wanna do is take this: and add a fourth number, that is being controlled be a sum of two of the other numbers. But I can't figure it out how to add the two numbers on top of each other. So I either need to understand that, or come up with a way to have a slider on my text layer that simply controls the number.