# Tutorial 14: Animated Numbers

In this tutorial, I will show you few methods of animating numbers in After Effect with help of a Slider Control or Angle Control effect. I will cover the following methods:

• Basic number animation with rounding numbers up
• Adding desired number of decimal points
• Adding custom prefixes and suffixes to your numbers e.g. \$ or %
• Adding commas to your large numbers – this method uses expression and technique done by Sergei from UKRAMedia – please watch his tutorial for in-depth explanation
• And finally, most complex and unusual set up – adding commas, decimal places and prefixes to your large numbers, and displaying them in “correct” way e.g. – \$ 350,000.52 (minus sign always in front of a prefix)
• Bonus – changing colour of your animation, if your number is positive or negative

#### Overall Set Up

Overall, it is very easy to animate numbers with a Slider or Angle control – they will act as your animation drivers of sorts. Simply, link “Source Text” of your text layer, to a slider, add keyframes and you a pretty much done. This way, you can play with keyframes and Graph Editor and really nail the look and speed of your animation.

Below, I will point out few important things for each method, to keep in mind. In each scenario, you have to add a Slider Control or Angle Control to your Text Layer. Then link your Source Property to your slider to create animation. Finally, add expressions below for different results.

#### Math.round();

Copy to Clipboard

This method simply rounds your number down to whole value. If you want to get decimal places, you need to multiply your number, then divide it by the same value. For example:

• Math.round(num * 10)/10; //1 decimal place
• Math.round(num * 100)/100; //2 decimal place
• Math.round(num * 1000)/1000; //3 decimal place
• And so on ….

I am not a fan of using this method, as it is not consistent. It will round the numbers down to 0 decimal points, even if you use 3 decimal places. It simply rounds the number, to nearest whole number + decimal points. But if you get “whole number”, for example, 2.00 – After Effects will display 2 instead.

#### .value.toFixed();

Copy to Clipboard

This is my preferred method of getting decimal points in my animation. Simply change the value in the brackets of toFixed(), to a desired number of decimals. After Effects will do the rest.

#### Prefixes and Suffixes

Copy to Clipboard

If you need to use custom signs or suffixes or prefixes in your animation, this is the best way to do it. You are “feeding” After Effects Source Text property with a string of letters and a number value, which is animated.

It can be pretty much anything – whole sentences, symbols, single letters, even spaces and so on. This is very useful, if you want to use Text Animators on your number animation and animate everything at once on one layer.

#### Large Numbers

Copy to Clipboard

Slider Control cannot handle numbers above 1 million or below negative 1 million. This is why you have to use Angle Control instead or Point Control, too.  Personally, I prefer to use Angle Control, as you are dealing with a single value and not an Array.

The easiest way to adjust the values of Angle Control, is to “zero” the first Number (the one that goes 1x, 2x and so on) and change Angle field, to number you desire. After Effects will run a calculation and it will adjust everything accordingly.

#### Large Numbers with Commas

Copy to Clipboard

Credit for this solution goes to Sergei from UKRAMedia.com and his excellent tutorial explaining in and outs of this method. Watch it for in depth explanation.

If you would like to learn more about this expression, I recommend visiting RegExr website. You will be able to test RegEx expressions and learn more what they mean. In short, they simply scan your string of values (text and numbers) and do a command – replacing or adding or removing values. It can be a letter or a number or a series of words you specify.

#### Advanced Large Numbers with Commas

Copy to Clipboard

This is the most complex and specific use case set up of this tutorial. This expression with a function:

• Adds decimal places to a number, which is linked to a slider
• “Scan” the whole value for numbers only, and adds a comma, every 3rd number it finds, after decimal only
• Then “scans” new string again for a minus sign (-), and if it finds it, it replaces it with a new string of values – in this case “- \$”
• Then we specify 2 variables, one for positive numbers, and one for negative numbers
• Positive variable adds prefix, before the final number with commas
• Negative does not add anything – it simply runs the function above
• Final step is do use a logic if statement, to check if we have a positive value and negative value, then use appropriate variable we specify above

There might be a better solution to the above method. Both variables are being calculated (posNum and negNum) and we are doing the logical check every frame. If we have to use lots of numbers and do this calculation on every frame – it could make the render time quite long, very quickly.

#### Bonus: Reactive Colours

Copy to Clipboard

As a small extra tip, I have included a solution on how to automatically change the colour of your numbers. This expression lets you swap colours, if your number is either positive or negative. For example, green for positive and red for negative values.

By using 2 separate Color Control effects, we can easily swap between colours, if the values from a slider are negative or positive. This is a very easy solution, as everything is driven by one slider, which animates Number values on a text layer.

# Examples in action

Below, you can see examples of animated numbers with various properties added to them – prefixes, commas, decimals and so on.

#### Get Project File From Gumroad

This project file contains all the assets necessary to make animation in the tutorial in final form. Everything is labeled, linked, with expressions and ready to use, if you wish to make your own version or just play around with it.

If you have any suggestions for tutorials or how I can improve, please do get in touch. I would love to hear from you.