0

I have a text layer (property: Source Text) connected to a slider control, in the way that the slider goes from 0 to 40 and the text layer simply follows the same amount.

Now, I want to have a fixed symbol which it will be "%" next to the number but of course with the current expression:

effect("Slider Control")("Slider")

It is not possible to have a symbol since the expression tells the text layer to follow the value of the slider.

Must be super simple but I don't have the knowledge to fix the expression.


The final result would be the text layer going from 0% to 40%

Thanks in advance.

1 Answer 1

1

To add text items together in Javascript is super easy, you just use the + operator, which is 'overloaded' so that when the either term in an expression x + y is a string, the output is the first and second terms concatenated, as a string.

So you can just use + "%" to add a "%" symbol to the end of a number. Works for any character, e.g. 123 + "-foo" would result in 123-foo.

TL;DR:

effect("Slider Control")("Slider") + "%" 

Note that the result of the slider will be a float (i.e. a number with lots of decimal places). That might not be what you're looking for. You can round it to an integer by using the Math functions, specifically Math.round (rounds to nearest integer) or Math.floor (always rounds down).

Math.round(effect("Slider Control")("Slider")) + "%" 

For extra credit: If you did want some decimal places, say 2 decimal places, then multiply the number by 100, round it and then divide by 100:

Math.round(100 * effect("Slider Control")("Slider"))/100 + "%" 
2
  • It was easy! Thank you so much, your answer will be really helpful when playing with this kind of string. Jan 4, 2019 at 8:50
  • 1
    The Adobe docs for expressions are here: helpx.adobe.com/after-effects/using/expression-basics.html I'd also suggest having a look at some basic JavaScript tutorials such as the ones at w3schools.com/js/default.asp Although aimed at Web development a lot of it is applicable for expressions, including some JS features not documented in the Adobe docs.
    – stib
    Jan 4, 2019 at 10:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.