Skip to main content
Participant
Mar 27, 2020 6:42 PM UTC
Question

Adding comma to Numbers in Expression Counter

Hi All,

 

I'm new to expression controls in after effects. I have a number counter and I've tried a few different approaches to this (Slider control and a longer string of expression code). Ultimately I decided to use this simple control as it allowed me to control how the numbers jump quite easily:

beginTime = 0;
endTime = 3.5;
startVal = 29219;
endVal = 20188;

Math.round(linear(time,beginTime,endTime,startVal,endVal)/200)*200

 

The problem is I cant seem to get a comma built in. Not sure if this is because I am trying legacy methods with a JavaScript project. Help if possible. Thank you!

6 replies

JohnColombo17100380
Community Manager
Community Manager
Mar 27, 2020 9:13 PM UTC

Hi RMI_1,

The new JavaScript expression engine makes formatting numbers very easy, much easier than a 30+ line function. To ensure you're using the JavaScript engine, go to File > Project Settings... > Expressions tab > set "Expressions Engine" to "JavaScript". It's the default so you are likely already using it.

 

Then modify your last line and add one more, as in the following example:

var num = Math.round(linear(time,beginTime,endTime,startVal,endVal)/200)*200;
new Intl.NumberFormat( "en-US", { useGrouping: true } ).format( num );

 

For more information on how to use Intl.NumberFormat, check out https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NumberFormat. You can format dates, currency, etc and it's all handled by the NumberFormat object. Feel free to reply back with any additional questions.

 

Cheers,

- John, After Effects Engineering Team 

Translate
Tomas B. aka Tom10
Inspiring
Sep 9, 2020 5:30 AM UTC

Hey John, this is just great, thank you for sharing!

Translate
Roland Kahlenberg
Legend
Mar 27, 2020 9:00 PM UTC
Very Advanced After Effects Training | Adaptive & Responsive Toolkits | Intelligent Design Assets (IDAs) | MoGraph Design System DEV