Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Forums Adobe After Effects Expressions Text layer looking at slider with an addition and keeping to two decimal places

  • Text layer looking at slider with an addition and keeping to two decimal places

  • Ashley Aslett

    September 17, 2021 at 8:21 pm

    Hi,

    I have a text layer looking at a slider control, I want to add 2 to the number that it is looking at. I guess something like this:

    thisComp.layer(“% P&L”).effect(“Slider Control”)(“Slider”)+2

    However I want to keep the resulting number to 2 decimal places, I know you can use the following but not sure where to add this into the above expression as keep getting errors?

    .value.toFixed(2)

    Any help greatly appreciated!

  • Dan Ebberts

    September 17, 2021 at 8:27 pm

    Something like this should work:

    (thisComp.layer("% P&L").effect("Slider Control")("Slider")+2).toFixed(2)
  • Fabrice Leconte

    September 17, 2021 at 8:28 pm

    Hello,

    Try something like this:

    (thisComp.layer('% P&L').effect('Slider Control')('Slider')+2).toFixed(2);

  • Ashley Aslett

    September 17, 2021 at 8:30 pm

    Dan you are an absolute hero, saved my bacon again!

    Fabrice thanks also for the super swift reply.

    Sending huge thanks both your ways!

  • Ashley Aslett

    September 17, 2021 at 8:58 pm

    Last one, I promise!!

    Can either of you help with the below:

    “$”+ num = (thisComp.layer(“% P&L”).effect(“Slider Control”)(“Slider”)*10000000).toFixed(0);

    function addCommas(x) {

    return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, “,”);

    }

    addCommas(num)

    Basically I have a text layer looking at a slider, multiplying that number by 10,000,000, keeping it to two decimal places and adding in commas….however I want a dollar sign at the start.

    Searching around I came up with the above but the $ symbol is not showing.

    As always your help is appreciated.

  • Ashley Aslett

    September 17, 2021 at 9:03 pm

    All good chaps, just figured it out by switching it around!…

    num = “$”+ (thisComp.layer(“% P&L”).effect(“Slider Control”)(“Slider”)*10000000).toFixed(0);

    function addCommas(x) {

    return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, “,”);

    }

    addCommas(num)

  • Fabrice Leconte

    September 17, 2021 at 10:44 pm

    Yes or you can use Intl.NumberFormat

    Intl.NumberFormat('en-US', {

    style: 'currency',

    currency: 'USD',

    minimumFractionDigits: 0

    }).format((thisComp.layer('% P&L').effect('Slider Control')(1) * 10000000));

  • Ashley Aslett

    October 13, 2021 at 3:14 pm

    Hey guys, one more question on the above!

    When inputting the following number on the below script -0.1742331 the output is $-1,742,331. Is there a way to change the script so the output is -$1,742,331…the minus symbol comes before the dollar sign rather than after it?

    num = “$”+ (thisComp.layer(“% P&L”).effect(“Slider Control”)(“Slider”)*10000000).toFixed(0);

    function addCommas(x) {

    return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, “,”);

    }

    addCommas(num)

    As always any help would be super appreciated!

  • Dan Ebberts

    October 13, 2021 at 7:18 pm

    Try it this way:

    n = thisComp.layer("% P&L").effect("Slider Control")("Slider");

    sign = n < 0 ? "-" : "";

    num = sign + "$"+ (Math.abs(n)*10000000).toFixed(0);

    function addCommas(x) {

    return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");

    }

    addCommas(num)

  • Ashley Aslett

    October 17, 2021 at 3:06 pm

    As always, worked perfectly!

    Your help is super appreciated! Thanks

Viewing 1 - 10 of 10 posts

Log in to reply.

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