Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Dan-Expression for Counting

  • Dan-Expression for Counting

    Posted by Tom Daigon on July 16, 2005 at 5:00 pm

    Hi Dan. I need a counter to count up from 7,000 to 13,000 within a 30 second period of time. It also needs to allow me to change the start, end and duration amounts. I tried altering the money counter you helped me with by deleting the last line of the expression, which deleted the “$” and the “,” , so I ended up with a counter that did not have commas (ie. 7000 as opposed to 7,000). Your help is appreciated!
    Tom

    Paul Roper replied 4 years ago 9 Members · 21 Replies
  • 21 Replies
  • Mylenium

    July 16, 2005 at 6:24 pm

    Hi, I’m obviously not Dan, but I’ll give it a try.

    start_value=7000;
    end_value=13000;
    ani_time=30;

    diff_value=end_value-start_value;
    time_value=diff_value/ani_time;
    out_value=time_value*time;

    [out_value]

    Apply this as usual to the source text property.

    Mylenium

    [Pour Myl

  • Tom Daigon

    July 16, 2005 at 7:33 pm

    Thanks Millenium, but no go. I copied and pasted the expression to the text property and it starts
    counting at 0 and ends at 994.00000000 with lots of places following after the decimal.
    Dans expression for the money counter is this…

    This is an expression for the source text of a text layer that should do the trick. Use a monospaced font or set kerning to 0:

    startValue = 64122205;
    endValue = 85302264;
    dur = 30; //seconds

    s = “” + Math.round(linear(time,0,dur,startValue,endValue));
    “$” + s.substr(0,2) + “,” + s.substr(2,3) + “,” + s.substr(5,3)

    Tom

  • Dan Ebberts

    July 16, 2005 at 9:19 pm

    Tom,

    Try this:

    startValue = 7000;
    endValue = 13000;
    dur = 30; //seconds

    Math.round(linear(time,0,dur,startValue,endValue));

  • Tom Daigon

    July 16, 2005 at 9:29 pm

    Thanks Dan. It is the same thing I tried when I deleted the last line of the Money Counter you helped me with a while back. The problem is the comma after the 1000s position (ie. 7000 vs 7,000) is gone.
    How do you add a comma to the equation…And could you give me a laymans explanation of what the expression is telling AE to do?

    startValue = 7000;
    endValue = 13000;
    dur = 30; //seconds

    Math.round(linear(time,0,dur,startValue,endValue));
    Thanks!
    Tom

  • Dan Ebberts

    July 16, 2005 at 9:53 pm

    Oh, you want the comma. I get it now. 🙂

    This should do it:

    startValue = 7000;
    endValue = 13000;
    dur = 30; //seconds

    s = “” + Math.round(linear(time,0,dur,startValue,endValue));
    s.substr(0,s.length-3) + “,” + s.substr(-3,3)

    It will only work for values from 1,000 to 999,999

    The tricky part of the expession is just converting the number to a string and then manipulating the string (using the JavaScript substr() method) to split the string into two pieces an stick a comma in between. You may need to dig into a javaScript reference to really figure it out.

    Dan

  • Tom Daigon

    July 16, 2005 at 10:09 pm

    Yes sir, that did the trick. Thanks for the tip on where I can get info for understanding what substrings are and what it means to split them (And this enthusiasm from someone who still has nightmares about high school math class!).
    Your help is truly appreciated.
    Tom

  • Kyle Norby

    April 29, 2009 at 7:15 pm

    Hello!

    I have a similar question regarding this expression. I would like to add a comma with this expression:

    //start

    val = effect(“Slider Control”)(“Slider”);
    numDec = 2; // digits to right of decimal
    numDigit = 0; // digits to left of decimal

    if (val < 1000000) sign = "" else sign = ""; s = Math.abs(val).toFixed(numDec); while (s.length < numDigit + numDec + 1) s = "0" + s; sign + s //end Thanks in advance!

  • Jason Snell

    April 4, 2012 at 1:57 pm

    Works great, BUT, I need to add another comma because of how great/long the number is, is there anyway you could help? Thanks!

    startValue = 0;
    endValue = 120000000;
    dur = 4; //seconds

    s = “” + Math.round(linear(time,0,dur,startValue,endValue));
    s.substr(0,s.length-3) + “,” + s.substr(-3,3)

  • Dan Ebberts

    April 4, 2012 at 4:13 pm

    This is one way:


    startValue = 0;
    endValue = 120000000;
    dur = 23; //seconds

    s = "" + Math.round(linear(time,0,dur,startValue,endValue));
    if (s.length > 6)
    s.substr(0,s.length-6) + "," + s.substr(-6,3) + "," + s.substr(-3,3)
    else if (s.length > 3)
    s.substr(0,s.length-3) + "," + s.substr(-3,3)
    else
    s

    Dan

  • Jason Snell

    April 4, 2012 at 9:20 pm

    Perfect! You are a saint!

Page 1 of 3

We use anonymous cookies to give you the best experience we can.
Our Privacy policy | GDPR Policy