Page 1 of 1
Attaching a comma... ?
Posted: May 17th, 2006, 11:12 am
by spiritform
Hey guys,
I have a text animation using numbers (i.e. 1200) that's animated along a path using the first margin attribute. A slider effect controls the source text value, which is then rounded to the nearest integer...
slideValue = Math.round(value);
And now, I'm trying to figure out a way via expression that will attach a comma to the value once it's greater than 999, so the number reads 1,200.
Any ideas?
Re: Attaching a comma... ?
Posted: May 17th, 2006, 12:37 pm
by Mylenium
spiritform wrote:Hey guys,
I have a text animation using numbers (i.e. 1200) that's animated along a path using the first margin attribute. A slider effect controls the source text value, which is then rounded to the nearest integer...
slideValue = Math.round(value);
And now, I'm trying to figure out a way via expression that will attach a comma to the value once it's greater than 999, so the number reads 1,200.
Any ideas?
if(x < 1000)
{my_string=Math.round(x)}
else {my_string= "1," + Math.round(x)}
You'd still have to take care of leading zeros and that stuff, so you might have better luck using modulus operators and assembling your string from their separate results, e.g
a=x%10;
b=x%100;
c=x%1000;
my_string=c+b+a;
Mylenium
Posted: May 17th, 2006, 2:05 pm
by spiritform
Thanks for your help Mylenium, but now I'm real confused.
Would x in this case be my slideValue? And where does my_string come into play? slideValue = my_string?
By the way, the expression on my Source Text reads...
effect("Slider Control")("Slider");
Actually, here's the file...
http://www.spiritform.com/number.aep
Posted: May 17th, 2006, 5:52 pm
by Dan Ebberts
This seems to work:
myStr = "" + Math.round(effect("Slider Control")("Slider"));
if (myStr.length > 3){
myStr.substr(0,myStr.length-3) + "," + myStr.substr(-3)
}else{
myStr
}
Dan
Posted: May 17th, 2006, 7:21 pm
by spiritform
That works like a charm Sir Ebberts... thanks for your help!
