Forums › Adobe After Effects › Technique for Animated Number Countdown with Commas
Technique for Animated Number Countdown with Commas
Randy Rubin
February 9, 2012 at 12:04 amHi All,
Ran into this issue and combined like two techniques to get a really easy solution – thought I’d share it.
To get a number to countdown (from say 256,000 to 152,000 with commas, no decimal) follow these steps. (I didn’t write most of the expression, got it from a website)
1. Create an empty text layer.
2. Go to Effects -> Expression Controls -> Slider Control
3. Twirl Down the Text Layer and ‘alt (option on mac) + click’ Text Source to open expression editor.
4. Enter the expression below.
5. Use the slider control effect to animate number. Enter the actual value instead of using the slider for numbers larger than one hundred. Simply key frame the effect and use the character editor to format the text. (Goes as high as 1,000,000)
Expression:
var num = effect(“Slider Control”)(“Slider”)
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;
}John Cuevas
February 9, 2012 at 1:14 amVery nice, saved to useful expressions folder.
Johnny Cuevas, Editor
Thinkck.com“I have not failed 700 times. I have succeeded in proving that those 700 ways will not work. When I have eliminated the ways that will not work, I will find the way that will work.”
—THOMAS EDISON on inventing the light bulb.Roland R. Kahlenberg
February 9, 2012 at 6:31 pmThanks for sharing Randy.
Cheers
RoRKIntensive AE & Mocha Training in Singapore and Malaysia
Adobe ACE/ACI (version 7) & Imagineer Systems Inc Approved Mocha TrainerAdam Lewen
June 10, 2012 at 7:49 pmThanks! This share helped me a lot!
Dan Smith
June 27, 2012 at 4:56 pmIs there a way to do 1,000,000+ ? I need a population counter….
Conrad DSouza
March 20, 2013 at 4:59 pmmy problem is the same as someone else posted; need to show a population countup from 0 or 100,000 to over 1 billion or over.
Ryan Paterson
July 15, 2013 at 9:30 pmThis is probably too late but I just saw this post now, to go over a million, just multiply the slider value in the first line of the expression like so-
var num = effect(“Slider Control”)(“Slider”) * 100 (or whatever number you want)
Marcello Sanna
April 30, 2014 at 6:02 pmThis is very useful, thanks for sharing!
In Italy we use commas instead of dots, so I would need to place the comma only before the last (or last two) digit.
I tried this wayvar num = effect(“Slider Control”)(“Slider”)
num = Comma(num);
[num]function Comma(number)
{
number = ” + Math.round(number);
if (number.length > 2)
{
var mod = number.length % 1;
var output = (mod > 0 ? (number.substring(0,mod)) : ”);
for (i=0 ; i < Math.floor(number.length / 1); i++)
{
if ((mod == 0) & (i == 0))
output += number.substring(mod+ 1 * i, mod + 1 * i + 1);
else
output+= ‘,’ + number.substring(mod + 1 * i, mod + 1 * i + 1);
}
return (output);
}
else return number;
}but I get a comma after every digit.
Any idea?
Thank you!Arvid Eriksson
April 17, 2015 at 2:18 amThank you for a simple and lean solution. Brilliant!
Arvid Eriksson
https://www.arvideriksson.com/stig olsen
September 28, 2015 at 11:04 amHi,
This expression actually adds a least 10 numbers behind the comma. How to avoid that?
Best, Stig
Log in to reply.