Expression to create a number with commas in After Effects

Requires After Effects 2020 or later.

If the expression isn't working go to: File > Project Settings > Expressions and make sure the dropdown is set to: Javascript

/**
* The following expression will format a number with 
* separators in After Effects
*/
var num = [YOUR NUMBER HERE];
num.toLocaleString();

Example usage:

/**
* Create a new text layer and set it to 2000
* Apply this to the Source Text property of the text layer
* Change the location value to your locale code
* e.g: German would be "de-DE"
* this will then format the text based on the locale rules
*/
var num = parseFloat(text.sourceText);
var location = "en-GB";
num.toLocaleString(location);

More advanced examples:

Create a counter with commas and decimals

Note: For this example, you will first need to do the following:

  1. Create a text layer
  2. Add a slider control to your text layer
  3. Add the following expression to the Source Text Value
var num = parseFloat(effect("Slider Control")("Slider"));
var location = "en-GB";
num.toLocaleString(location, {minimumFractionDigits: 2});

Create a counter with commas but no decimals

Note: For this example, you will first need to do the following:

  1. Create a text layer
  2. Add a slider control to your text layer
  3. Add the following expression to the Source Text Value
var num = parseFloat(effect("Slider Control")("Slider"));
var location = "en-GB";
num.toLocaleString(location, {minimumFractionDigits: 0});

Related Video: