Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions: Leading zeros and decimal places.

  • Navarro Parker

    January 2, 2013 at 6:20 pm

    Maybe 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 pm

    Something 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

    January 2, 2013 at 8:39 pm

    Works perfectly! It’s the best expression of 2013! 😉

  • Navarro Parker

    May 29, 2013 at 9:34 pm

    Hi 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 pm

    Try 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;
    s

    Dan

  • Navarro Parker

    May 30, 2013 at 1:28 am

    Yup, that does it! Thank you!

  • Nelson Rayner

    September 24, 2014 at 12:25 pm

    Hey 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 am

    I 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

Page 2 of 2

We use anonymous cookies to give you the best experience we can.
Our Privacy policy | GDPR Policy