ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

counter with slider and percentage

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Jason Jantzen
counter with slider and percentage
on Jul 22, 2013 at 10:10:22 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


Return to posts index

Dan Ebberts
Re: counter with slider and percentage
on Jul 22, 2013 at 11:57:12 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



Return to posts index

Jason Jantzen
Re: counter with slider and percentage
on Jul 23, 2013 at 12:16:28 am

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

Jason Jantzen
vimeo.com/jasonj


Return to posts index


michal swarowski
Re: counter with slider and percentage
on Jul 16, 2015 at 9:03:27 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?


Return to posts index

Dan Ebberts
Re: counter with slider and percentage
on Jul 16, 2015 at 1:39:57 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



Return to posts index

michal swarowski
Re: counter with slider and percentage
on Jul 16, 2015 at 6:21:35 pm
Last Edited By michal swarowski on Jul 16, 2015 at 6:24:37 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


Return to posts index


michal swarowski
Re: counter with slider and percentage
on Jul 16, 2015 at 6:30:13 pm
Last Edited By michal swarowski on Jul 16, 2015 at 6:32:47 pm

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



Return to posts index

Kevin Camp
Re: counter with slider and percentage
on Jul 18, 2015 at 9:07:58 pm

Try simplifying the expression to this:

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

Kevin Camp
Art Director
KCPQ, KZJO & KRCW


Return to posts index

Liran Tabib
Re: counter with slider and percentage
on May 10, 2018 at 6:55:12 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:
http://www.vdodna.com/products/counter-preset/

Liran Tabib
http://www.vdodna.com


Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2018 CreativeCOW.net All Rights Reserved
[TOP]