Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions counter with slider and percentage

  • counter with slider and percentage

    Posted by Jason Jantzen on July 22, 2013 at 10:10 pm

    I think I copied this from a post Dan made

    slider = effect("Slider Control")("Slider");
    numDecimals = 0;
    commas = false;
    dollarSign = false;
    s = slider.value.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;
    }

    But I need % instead of a $ sign. I can figure out easy enough how to change the symbol, but I’m not entirely sure how to switch prefix to suffix.

    Jason Jantzen
    vimeo.com/jasonj

    Liran Tabib replied 8 years ago 5 Members · 8 Replies
  • 8 Replies
  • Dan Ebberts

    July 22, 2013 at 11:57 pm

    This should work:


    slider = effect("Slider Control")("Slider");
    numDecimals = 0;
    commas = false;
    dollarSign = false;
    percentSign = true;
    s = slider.value.toFixed(numDecimals);
    prefix = "";
    suffix = "";
    if (s[0] == "-"){
    prefix = "-";
    s = s.substr(1);
    }
    if(dollarSign) prefix += "$";
    if(percentSign) suffix = "%";
    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 + suffix;
    }else{
    prefix + s + suffix;
    }

    Dan

  • Jason Jantzen

    July 23, 2013 at 12:16 am

    Thanks Dan! This will be very useful with the option to use dollar sign or %.

    Jason Jantzen
    vimeo.com/jasonj

  • Michal Swarowski

    July 16, 2015 at 9:03 am

    Hi. i have animation counting from 0 % to 100 %
    with this code i have 100,0 %. How to remove decimate and live only integer on the end of animation?

  • Dan Ebberts

    July 16, 2015 at 1:39 pm

    You shouldn’t have a decimal point with the code I posted above. Did you make any changes to it? Please post what you have.

    Dan

  • Michal Swarowski

    July 16, 2015 at 6:21 pm

    hi,
    first i used this code: Math.round(effect(“Slider Control”)(“Slider”)) + ” %”

    …but this expression count with points. I don`t know if it`s any possibility to add commas to it or not.

    Than i tried to paste Your expression but the counts are integer, not decimate. I changed the values in it, but the animation are other than i expected

  • Michal Swarowski

    July 16, 2015 at 6:30 pm

    this is my screen. on the end of animation i have decimate not integer. I don`t know how to change this

  • Kevin Camp

    July 18, 2015 at 9:07 pm

    Try simplifying the expression to this:

    slider = effect(“slider control”)(“slider”);
    “” + Math.floor(slider) + “%”

    Kevin Camp
    Art Director
    KCPQ, KZJO & KRCW

  • Liran Tabib

    May 10, 2018 at 6:55 am

    You can also use Counter Preset to create any Counter and running numbers animation, with any kind of symbol or character (%,$ etc.). I hope you will find it useful. you can get it here:
    https://www.vdodna.com/products/counter-preset/

    Liran Tabib
    http://www.vdodna.com

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