-
Technique for Animated Number Countdown with Commas
Hi 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;
}