Activity › Forums › Adobe After Effects › Expressions: Leading zeros and decimal places.
-
Expressions: Leading zeros and decimal places.
Quba Michalski replied 11 years, 10 months ago 6 Members · 18 Replies
-
Navarro Parker
January 2, 2013 at 6:20 pmMaybe we should start over with the original question: How would you get leading zeroes *and* and fixed decimals in one expression?
So I could get counters to display values like : “000126.5700” or “005.00”
-
Dan Ebberts
January 2, 2013 at 8:00 pmSomething like this should work:
num = thisComp.layer("Deep Lime Green Solid 1").effect("Slider Control")("Slider").value;
numDigits = 5;
numDec = 2;s = "" + Math.floor(num);
while(s.length < numDigits) s = "0" + s;
if (numDec > 0) s += "." + num.toFixed(numDec).split(".")[1];
s
Dan
-
Navarro Parker
May 29, 2013 at 9:34 pmHi Dan!
I ran into a tiny problem with this expression. It doesn’t respect the number of leading zeros with negative numbers.
-
Dan Ebberts
May 29, 2013 at 9:48 pmTry it this way:
num = thisComp.layer(“Deep Lime Green Solid 1”).effect(“Slider Control”)(“Slider”).value;
neg = num < 0;
num = Math.abs(num);
numDigits = 5;
numDec = 2;
s = “” + Math.floor(num);
while(s.length < numDigits) s = “0” + s;
if (numDec > 0) s += “.” + num.toFixed(numDec).split(“.”)[1];
if (neg) s = “-” + s;
sDan
-
Nelson Rayner
September 24, 2014 at 12:25 pmHey guys,
Just wondering if anyone knows a way to also add commas into the equation? So you’ve got a Dollar sign, leading zeros, and commas?
Thanks!
-
Quba Michalski
September 25, 2014 at 1:10 amI have created this “little behemoth” called UberNumber to do just that (everything). Check it out at: https://qubahq.com/2014/06/ubernumber/
Quba Michalski
qubahq.com
Reply to this Discussion! Login or Sign Up