Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity › Forums › Adobe After Effects Expressions › [Help] automatically add "+" if value is positive

  • [Help] automatically add "+" if value is positive

    Posted by Arno Wolk on August 25, 2021 at 11:55 am

    Hi Guys,
    I wonder if anyone can point me in the right direction with this simple expression.
    I want to show the percentage change of a political party. If the value is negative, After Effects will show me a minus accordingly, but I want to automatically add a plus symbol, if the value is positive.
    I have a slider control (s) where I will input the current data. 10 is the historical value which the value form the slider will be compared to.
    So far this is my expression (1 demical after the comma)

    s = thisComp.layer(“CTRL”).effect(“party_1”)(“Slider”)-10
    d = 10;
    x = Math.round(s*d)/d

    x.toString().replace(“.”, “,”)+ “%”


    I tried a simple if-expression, but it would give me an error. Guess the expression can’t return a string?

    s = thisComp.layer(“CTRL”).effect(“party_1”)(“Slider”)-10
    d = 10;
    u = if(s>0) {“+”};
    x = Math.round(s*d)/d
    u + x.toString().replace(“.”, “,”)+ “%”

    I’m thankful for any kind of help 🙂

    Arno Wolk replied 5 years, 1 month ago 2 Members · 2 Replies
  • 2 Replies
  • Dan Ebberts

    August 25, 2021 at 4:30 pm

    Try replacing this:

    u = if(s>0) {"+"};

    with this:

    u = s>0 ? "+" : "";

  • Arno Wolk

    August 26, 2021 at 1:01 pm

    Hi Dan,

    worked like a charm 🙂 thank you!!!

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