Animating numbers in After Effect is one of those things that should be easy – but isn’t.
In this post, I’ll show you how to set up a number animation slider in After Effects and some basic expressions to clean up the formatting.
Before we get too deep into expressions, check out Num – a 100% free tool that will do all the number formatting in After Effects for you. But if you’d rather learn how to do it yourself, read on.
If you’re working with numbers in After Effects, the best place to start is a text layer. Since we’ll be controlling the actual number with expressions, you can use whatever text you want as the placeholder.
In order to animate the numbers, you’ll need to add an expression slider. This will give you an easy way to control and keyframe whatever the actual number is.
With your text layer selected, apply a slider control.
Effects > Expression Controls > Slider Control
A slider by itself won’t do anything – you need to link your source text to the slider.
Twirl down to the Source Text of your text layer. Using the Property Pick Whip, click and drag it to the layer’s slider control.
The following expression will automatically be created and the text will now be linked to the value of the slider control.
You can now keyframe and animate the slider, but as you do, you’ll notice something off... After Effects is a little too precise with displaying your number – and usually, for animation, you’ll want to simplify the formatting.
You can easily eliminate decimals altogether, by using the Math.round() function.
Open your Source Text expression, and replace it with the following:
Notice that this still uses the slider effect from the original expression, but wraps it in the Math.round() function.
If you’d like to be a bit more precise, while still keeping your numbers neat, you can use the .toFixed() function.
Open your Source Text expression, and replace it with the following:
This also uses the original slider expression. Notice that .value is added after the slider effect.
The 2 in the expression above means After Effects will display 2 decimal places (i.e. “1.00”). You can change this number to control the amount of decimal places.
If you’re working with a number over 999, chances are you’d like to use some commas – or thousand separators. The good news is that this this can be done with the .toLocaleString() function, but the downside is that it won’t work with decimal places at all.
Open your Source Text expression, and replace it with the following:
Make sure your expression engine is set to JavaScript, otherwise this function will not work!
Here are few more advanced functions that can be used to help format numbers in After Effects:
While formatting numbers in After Effects isn’t the hardest thing ever, it is often a nuisance to try and remember all the expressions above while you’re in the middle of a project.
Even if you know the expressions, the syntax is inconsistent: some take the slider effect by itself, some take the .value of the slider, and some need to the slider effect to be converted to a string (.toString()).
Furthermore, many of these expressions cannot be used with one another. For example, something like “$1,000.00” is really difficult to format since .toFixed() and .toLocaleString() can’t be applied to the same value.
I made Num to make it easier and faster to format numbers in After Effects. And it’s completely free.