Overcoming limitations of the Numbers effect in After effects
Note that this tutorial was updated on July 3rd, 2007, and if you used it, or downloaded the project file, before that date there were a few errors which would cause the expression to not work in a few circumstances. These mistakes have since been changed.
If you have ever used the text > numbers, effect in AE you have probably become very frustrated with some problems it has. First of all, you numbers can not go any higher than 30000, or any lower than -30000. Secondly, there is no way to have commas automatically inserted into your numbers. Lastly, there is no way to round your number off to a certain amount of decimal points. After reading through this tutorial, you should be able to create something like this, using an expression for a text layer:

In this tutorial, you will learn how to link a text layer to an expression control which you can animate. The expression control will drive the number shown in the text layer. Using other sliders and controls, you will be able to tweak the number of decimals shown on the text layer, and if commas are used. If you don't care about how this expression works, jump to he bottom and download the .aep file.
First, add a "Null Object" to your comp. Name it Controls. Now, add a Slider Control effect to this layer. The slider control is found under Effect > Expression Controls > Slider Control. Name this slider control number. Next, add another slider control and name it amt_of_decimals. Lastly, add a Checkbox Control, and name it use_commas. At this point, the effect controls box for your Controls layer should look like this:

Now, create a text layer, and name it whatever you like.
Now that we are done with the initial setup, it's time to add some expressions. Twirl down to the sourceText property of the text layer, and input the following expression:
num = thisComp.layer("Controls").effect("number")("Slider");
amtOfDec = thisComp.layer("Controls").effect("amt_of_decimals")("Slider");
commas = thisComp.layer("Controls").effect("use_commas")("Checkbox");
//--
num = num + 0;
amtOfDec = amtOfDec + 0;
commas = commas == 1;
//--
if(! commas){
//commas not requested
num.toFixed( amtOfDec );
}else{
//commas requested
//This function takes a positive whole number as a string
//and adds commas to it
function addCommas( str ){
finalResult = "";
for( i = str.length - 1; i >= 0; i-- ){
finalResult = str.charAt( i ) + finalResult;
if( (str.length - i) % 3 == 0 && i != 0 )
finalResult = "," + finalResult;
}
return finalResult;
}
//--
intPart = Math.floor( Math.abs( num ) );
decPart = Math.abs(num) - intPart;
wasNeg = num < 0;
result = "";
if( wasNeg )
result = "-" + result;
intPartString = intPart + "";
decPartString = decPart.toFixed( amtOfDec ) + "";
decPartString = decPartString.substring( 1 );
result = result + addCommas( intPartString ) + decPartString;
result
}
This expression may seem a
bit overwhelming at first, but if you look at the expression in chunks,
its really not too hard to understand. Allright, lets start
looking through it piece by piece.

The first 3 lines here are just placing the values obtained from the slider controls we created into variables. However, lines 5-7 are a bit confusing. Lines 5-6 are telling After Effects to treat the variables num and amtOfDec as
numbers. If line 6 is removed, you will get an error because
later on in the expression, After Effects will "think of" amtOfDec as a
string (a sequence of characters) instead of a number. Line 7, is
just turning the commas variable
into a boolean variable. This part is confusing if you are a
non-programmer. If you really want to understand, wither drop me
an email.

Lines 9-11 here are pretty simple. Line 9 says, if we are not
going to use commas, perform the next few lines that are between the {}
brackets. Line 11 is just taking the value of num, and outputting
it to the specified number of decimals, using the toFixed() method.

Alright, the bulk of this code, lines 17-25, is concerned with creating
our own function, which we can use to add commas to a number.
This function takes in a sequence of characters, called a string
in programming terms, and adds commas to it. First it created an
empty string, called finalResult which
is the value that the function will return. Lines 19-23 are a
loop, which starts at the end of the string passed to the function and
moves towards the front. Every time the loop is executed, it adds
a character to finalResult.
However, lines 21 and 22 are where the actual comma adding
occurs. These 2 lines use an if statement which adds a comma to finalResult every 3 characters, as long as the comma wont be added in the front.

These last few lines are pretty simple. Lines 27 and 28 are creating two new variables, intPart and decPart, which hold the integer part of num and the decimal part of num, respectively.
Lines 29-32 are just code to make sure a negative sign is
added if the number os negative. Line 35 is a bit confusing.
It is just making sure that the leading zero is stripped away from the
decimal part of the number, otehr wise we would always have an extra
zero right before the decimal point.
Download the After Effects 7.0 Project File here