FORUMS: list search recent posts

scrolling numbers from 6000 to 30millions

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Anders Hattne
scrolling numbers from 6000 to 30millions
on Mar 1, 2011 at 11:09:51 pm

Hi,
I'm trying to get a scroll from 6000 to 30 millions using a txt layer and a slider.
I've modified an expression by Dan Ebberts to get me halfway into a mess. Don't really know what I'm doing.. but still:
num1=effect("Slider Control")("Slider");
num2=linear(num1,0,100000, 6000, 30000000); /* slider only goes to 1milion*/
s= " " + Math.floor(num2); /*don't know what this does but needs to be done so you can read the amount of characters*/
n = s.length;
if (n > 3)
{
s.substr(0,n-3) + "," + s.substr(-3); // separate with comas
}
if (n >5)
{
s.substr(0,n-6) + "," +s.substr(-6,n-5) + "," + s.substr(-3); //my messy modification
}
else
s


Right, the problem is the numbers above a thousand. I just played around and found that s.substr(-6,n-5)sort of worked but I end up with 4 numbers instead of 3. So the final number would be 16,6356,380. Also the first number stays 0 all the time, would be cool if that number could run as well..
My apologies if this is really messy, but it's late here with all what that means..
I'd be very happy if someone could clean this up for me!

Thanks!

num1=effect("Slider Control")("Slider");
num2=linear(num1,0,100000, 6000, 30000000);
s= " " + Math.floor(num2);
n = s.length;
if (n > 3)
{
s.substr(0,n-3) + "," + s.substr(-3);
}
if (n >5)
{
s.substr(0,n-6) + "," +s.substr(-6,n-5) + "," + s.substr(-3);
}
else
s


http://www.ardillamedia.com


Return to posts index


Dan Ebberts
Re: scrolling numbers from 6000 to 30millions
on Mar 2, 2011 at 12:19:26 am

I think this works:


num1=effect("Slider Control")("Slider");
num2=linear(num1,0,100000, 6000, 30000000); /* slider only goes to 1milion*/
s= "" + Math.floor(num2);
n = s.length;
if (n > 6){
s.substr(0,n-6) + "," + s.substr(-6,3) + "," + s.substr(-3)
}else if(n > 3){
s.substr(0,n-3) + "," + s.substr(-3);
}else{
s
}



Dan



Return to posts index

Anders Hattne
Re: scrolling numbers from 6000 to 30millions
on Mar 2, 2011 at 7:58:17 am

Yeah, works perfectly, thanks a lot!!

I'll have to figure out that substr operator. I once had a similar problem which I solved with a 18 line expression. Later I found your solution to the same problem in four lines..
Thanks again!

http://www.ardillamedia.com


Return to posts index


Anders Hattne
Re: scrolling numbers from 6000 to 30millions
on Mar 17, 2011 at 5:44:53 pm

...and since I always.. ALWAYS get completely lost when trying to figure out the decimals, I'm adding the expression for 10 digits. That way it might be easier for beginners like me to figure out how it works..

num1=thisComp.layer("number_controll").effect("Slider Control")("Slider");
num2=linear(num1,0,100000, 0, 13700000000); /* convierte de 0 a 100mil a 6mil a 30millones*/
s= "" + Math.floor(num2);
n = s.length;
if (n > 9){
s.substr(0,n-9) + "." + s.substr(-9,3)+ "." + s.substr(-6,3) + "." + s.substr(-3)
}
else if (n > 6){
s.substr(0,n-6) + "." + s.substr(-6,3) + "." + s.substr(-3)
}
else if(n > 3){
s.substr(0,n-3) + "." + s.substr(-3);
}
else{
s
}


http://www.ardillamedia.com


Return to posts index

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