← Back to blog
|
June 2, 2022

How to format numbers in After Effects

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.

Create a text layer

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.

How to add a number slider

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

How to link source text to slider

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.

effect("Slider Control")("Slider")

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.

How to round numbers in After Effects

You can easily eliminate decimals altogether, by using the Math.round() function.

Open your Source Text expression, and replace it with the following:

Math.round(effect("Slider Control")("Slider"))

Notice that this still uses the slider effect from the original expression, but wraps it in the Math.round() function.

How to limit decimal places in After Effects

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:

effect("Slider Control")("Slider").value.toFixed(2)

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.

How to add commas to numbers in After Effects

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:

effect("Slider Control")("Slider").value.toLocaleString()

Make sure your expression engine is set to JavaScript, otherwise this function will not work!

Other number formatting expressions

Here are few more advanced functions that can be used to help format numbers in After Effects:

  • padStart(targetLength, padString) - This can be used to add 0’s, X’s (or any string) to the beginning digits of a number to make the number have a fixed number of digits (i.e. “001”, “XX1”).
  • padEnd(targetLength, padString) - This can be used to add 0’s, X’s (or any string) to the ending digits of a number to make the number have a fixed number of digits (i.e. “100”, “1XX”).
  • “string” + - Add any string to the beginning or end of an expression to give a number more meaning (i.e. “$100”, “100%”)

Why I made Num

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.

Get Num for FREE

Get more After Effects tricks in your inbox.

Check your inbox.

Please confirm your email, so we can keep you in the loop.
Oops! Something went wrong while submitting the form.