Activity › Forums › Adobe After Effects Expressions › Leading Zeros
-
Leading Zeros
Posted by Christopher Johnstone on February 6, 2013 at 11:30 amHello,
Hello I am creating a counter in a text layer in After Effects.
is there a way in java script to count with leading zeros?
ie 000111.8, 000111.9, 000112.0 …Many thanks – Chris
Christopher Johnstone
Dan Ebbertsreplied 13 years, 7 months ago 3 Members · 5 Replies
-
5 Replies
-
Todd Kopriva
February 6, 2013 at 3:30 pmThis search got me here:
https://forums.creativecow.net/thread/2/863343#863343———————————————————————————————————
Todd Kopriva, Adobe Systems Incorporated
After Effects quality engineering
After Effects team blog
——————————————————————————————————— -
Christopher Johnstone
February 6, 2013 at 6:09 pmSo the expression below works beautifully – thank you.
I am now trying to generate a colour change on the leading zeros.The effect I am after is If the leading zero is in the 10, 100, 1000 + column I would like to generate a colour change and if a leading zero is in the 1 column it needs to remain the same.
To explain a little further in the following strings:
“00000.0” or “00001.0”
The first four zeros would be effected by the colour change.
The fifth 0 would not.“00010.0”
The first three zeros would be the only ones effected by the colour change.“00100.0”
The first two zeros would be the only ones effected by the colour change.“10000.0”
No zeros would be effected by the colour change.Hopefully my explanation made sense?
Let me know if you have any ideas?
Many thanks – Chris
num = comp("name").layer("name").effect("name")("Slider");
numDigits = 6;
numDec = 1;s = "" + Math.floor(num);
while(s.length < numDigits) s = "0" + s;
if (numDec > 0) s += "." + num.toFixed(numDec).split(".")[1];
sChristopher Johnstone
-
Dan Ebberts
February 6, 2013 at 8:11 pmIf you add a fill color Animatior, set it to your leading zero color, add an Expression Selector, delete the Range Selector, and add this experssion to the Amount property of the Expression Selector, I think it will do what you want:
s = text.sourceText;
r = 100;
for (i = 1; i <= textIndex; i++){ if (s[i-1] != "0"){ r = 0; break; } } rDan
-
Dan Ebberts
February 6, 2013 at 8:19 pmOops. Thank doesn’t quite do it. I didn’t read your question close enough. Be back in a bit…
Dan
-
Dan Ebberts
February 6, 2013 at 8:28 pmIf you always have five digits to the left of the decimal, I think this will work:
if (textIndex > 4) {
0
}else{
s = text.sourceText;
r = 100;
for (i = 1; i <= textIndex; i++){
if (s[i-1] != "0"){
r = 0;
break;
}
}
r
}
Dan
Reply to this Discussion! Login or Sign Up