Videos with number animations look slick. Why just display a static number or percentage on screen when you can have an animation scrolling the numbers up to your target number?

You can create many numeric animations efficiently with just one layer in your composition by applying the Slider Control effect and using an expression. I get a lot of questions about how to do this, as figuring out the proper expression can be confusing when it comes to rounding numbers or adding commas to large numbers.

Well, wonder no more! My video tutorial will show you a couple key expressions you need to know when dealing with this situation. Advanced knowledge of expressions is not needed, you just need to know how to copy and paste. You’ll learn how to apply the Slider Control and create the expression. Then, you’ll learn how to amend the expression based on if you are trying to round the number to a whole number, have a select number of digits after the decimal point, and/or add a comma in the number.

I’ve provided the expressions below the video for your copy/paste needs, so just watch the video to see where and how to place them.

Note that creating an expression is done by doing an Alt-click (Windows) or Option-click (Mac) on the stopwatch icon in the layer’s property. Whenever you link the source text property of your layer to the slider control value, you’ll see this text appear in the expression area:

effect(“Slider Control”)(“Slider”);

However, when your numbers scroll between set keyframes, you’ll have a lot of digits after the decimal. To alleviate this, you need to tell After Effects to round the number. In my opinion, the quickest way to do this is to amend the expression to the following:

Math.round(effect(“Slider Control”)(“Slider));

Note that capitalization matters. It has to be Math, not math. Now, you will have whole numbers with no decimal point.

If you want to add a comma to your number value so you get 1,000 instead of 1000, the expression is quite complex. This is where copy and paste come into play. Erase what you have in the expression area and paste this:

num = effect(“Slider Control”)(“Slider”).value.toFixed();

return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, “,”);

}

Breaking this down, the top line provides what the variable equals. “Slider Control” is whatever you name the Slider Control effect. By default, it is Slider Control, but some people rename their effects.

Adding .value.toFixed() is important (note the capital “F”). Without this addition, your number will have a significant amount of digits after the decimal point. Inside the parenthesis, you can add a numeric value. This value will be how many digits you want to see after the decimal point. To add two digits after the decimal point, the expression is as follows:

num = effect(“Slider Control”)(“Slider”).value.toFixed(2);