Attaching a comma... ?

Moderators: Disciple, zlovatt

Post Reply
spiritform
Posts: 3
Joined: May 16th, 2006, 4:04 pm
Location: Los Angeles
Contact:

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?
Mylenium
Posts: 139
Joined: July 20th, 2005, 12:07 am

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
[Pour Mylène, ange sur terre]
spiritform
Posts: 3
Joined: May 16th, 2006, 4:04 pm
Location: Los Angeles
Contact:

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
Dan Ebberts
Posts: 320
Joined: June 26th, 2004, 10:01 am
Location: Folsom, CA
Contact:

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
spiritform
Posts: 3
Joined: May 16th, 2006, 4:04 pm
Location: Los Angeles
Contact:

That works like a charm Sir Ebberts... thanks for your help! :)
Post Reply