# Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Forums Adobe After Effects Technique for Animated Number Countdown with Commas

• # Technique for Animated Number Countdown with Commas

25 Members · 27 Posts
• ### Kolitha Bandara

November 24, 2015 at 5:49 am

var num = effect(“Slider Control”)(“Slider”)*10
num = Comma(num);
[num]

function Comma(number)
{
number = ” + Math.round(number);
if (number.length > 3)
{
var mod = number.length % 3;
var output = (mod > 0 ? (number.substring(0,mod)) : ”);
for (i=0 ; i < Math.floor(number.length / 3); i++)
{
if ((mod == 0) && (i == 0))
output += number.substring(mod+ 3 * i, mod + 3 * i + 3);
else
output+= ‘,’ + number.substring(mod + 3 * i, mod + 3 * i + 3);
}
return (output);
}
else return number;
}

• ### Nick Hamilton

November 26, 2015 at 12:07 pm

And if you would like to count over 1,000,000 and keep the comma’s in:

startCount = 0;
endCount = 48000000;
countDur = 3;

var num = Math.round(linear(time,0,countDur,startCount,endCount))
num = Comma(num);
[num]

function Comma(number)
{
number = ” + Math.round(number);
if (number.length > 3)
{
var mod = number.length % 3;
var output = (mod > 0 ? (number.substring(0,mod)) : ”);
for (i=0 ; i < Math.floor(number.length / 3); i++)
{
if ((mod == 0) && (i == 0))
output += number.substring(mod+ 3 * i, mod + 3 * i + 3);
else
output+= ‘,’ + number.substring(mod + 3 * i, mod + 3 * i + 3);
}
return (output);
}
else return number;
}

• ### Liran Tabib

April 22, 2016 at 7:12 am

you can use a different approach and create the animation with the counter preset: https://www.vdodna.com/products/counter-preset/

• ### David Crowther

April 24, 2017 at 8:00 am

New response to old post, this helped me a lot with a project I am working on. However, I used point control instead of slider to overcome the arbitrary 1,000,000 limit.

The expression was (including commas):

var num = effect(“Point Control”)(“Point”)[0]

num = Comma(num);
[num]

function Comma(number)
{
number = ” + Math.round(number);
if (number.length > 3)
{
var mod = number.length % 3;
var output = (mod > 0 ? (number.substring(0,mod)) : ”);
for (i=0 ; i < Math.floor(number.length / 3); i++)
{
if ((mod == 0) && (i == 0))
output += number.substring(mod+ 3 * i, mod + 3 * i + 3);
else
output+= ‘,’ + number.substring(mod + 3 * i, mod + 3 * i + 3);
}
return (output);
}
else return number;
}

• ### Jameel Choudhury

June 20, 2017 at 2:12 pm

Hi David,

This expression is extremely helpful for what I need in my project. I just had 1 question, how do I go about including a £ or \$ symbol at the beginning of the number as it counts up?

Thanks

• ### David Crowther

June 20, 2017 at 6:22 pm

Hi Jameel,

You can add it to the num variable like so:

var num = effect(“Point Control”)(“Point”)[0]

num = “\$” + Comma(num);
[num]

function Comma(number)
{
number = ” + Math.round(number);
if (number.length > 3)
{
var mod = number.length % 3;
var output = (mod > 0 ? (number.substring(0,mod)) : ”);
for (i=0 ; i < Math.floor(number.length / 3); i++)
{
if ((mod == 0) && (i == 0))
output += number.substring(mod+ 3 * i, mod + 3 * i + 3);
else
output+= ‘,’ + number.substring(mod + 3 * i, mod + 3 * i + 3);
}
return (output);
}
else return number;
}

• ### Jared Jordan

November 28, 2017 at 8:43 pm

Can you do this and have 2 decimal places after it too?

• ### Erik Waluska

October 30, 2018 at 4:54 pm

Exactly what I needed. Worked perfect. Thank you!!

Erik Waluska
EAWmedia

• ### Tomáš Lyga

November 6, 2018 at 12:19 pm

Hi, for some reason this code (or any other similar to this one) doesn’t work with Adobe After Effects CC 2019. Do you have any idea why is that? Thank you

• ### Magdalena Kašparová

March 8, 2019 at 11:46 am

In CC2019 first go to: File • Project Settings • Expressions ; set it to Legacy ExtendScript

Viewing 11 - 20 of 27 posts