Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Adding comma to Numbers in Expression Counter

New Here ,
Mar 27, 2020 Mar 27, 2020

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!

TOPICS
Expressions , How to
14.7K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Mar 27, 2020 Mar 27, 2020

Did you go through this thread?

https://community.adobe.com/t5/after-effects/ae-add-commas-to-number-counting-in-expressions/td-p/93...

Very Advanced After Effects Training | Adaptive & Responsive Toolkits | Intelligent Design Assets (IDAs) | MoGraph Design System DEV
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Employee ,
Mar 27, 2020 Mar 27, 2020

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
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Sep 08, 2020 Sep 08, 2020

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jan 08, 2021 Jan 08, 2021

I just want to say...you're AWESOME! People on YouTube tried so many different ways to achieve this but this expression is perfect for the task at hand! Like, it can't get any better!

 

For those who don't prefer adding beginning time and end time in the expressions and want to use slider control instead:

var num = effect("Slider Control")("Slider").value.toFixed();
new Intl.NumberFormat( "en-IN", { useGrouping: true } ).format( num );

This specific expression is more appreciated by people living outside US as they have different Number Counting System so the comma doesn't always come after 3 digits. You can change "IN" from "en-IN" to your country.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Mar 23, 2021 Mar 23, 2021

Wow, thanks that helped alot! 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Oct 14, 2024 Oct 14, 2024
LATEST

I almost gave up on my project trying to find this exact expression. Thank you so much!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines