Parameters
| Variable | Default | Description |
|---|---|---|
| numDecimals | 0 | Number of decimal places to display |
| commas | false | Set to true to format thousands with commas (e.g. 1,000) |
| symbol | true | Prepend a symbol (default °) — change the string in the prefix line |
| beginCount | 34 | Starting number |
| endCount | 12 | Ending number (can be higher or lower than beginCount) |
| dur | 2 | Duration of the count animation in seconds |
How to use it
Create a Text layer in After Effects.
With the layer selected, open the Text > Source Text property in the timeline.
Hold Alt / Option and click the stopwatch on Source Text to open the expression editor.
Paste the expression below. Adjust the parameter variables at the top to match your needs.
The counter starts running from the layer's inPoint — trim or reposition the layer to control timing.
Expression
Source Text · After Effects
numDecimals = 0;
commas = false;
symbol = true;
beginCount = 34;
endCount = 12;
dur = 2;
t = time - inPoint;
s = linear(t, 0, dur, beginCount, endCount).toFixed(numDecimals);
prefix = "";
if (s[0] == "-") {
prefix = "-";
s = s.substr(1);
}
if (symbol) prefix += "°";
if (commas) {
decimals = "";
if (numDecimals > 0) {
decimals = s.substr(-(numDecimals + 1));
s = s.substr(0, s.length - (numDecimals + 1));
}
outStr = s.substr(-s.length, (s.length - 1) % 3 + 1);
for (i = Math.floor((s.length - 1) / 3); i > 0; i--) {
outStr += "," + s.substr(-i * 3, 3);
}
outStr + decimals + prefix;
} else {
s + prefix;
}
Further reading
For a detailed breakdown of how this expression works, visit the original documentation at motionscript.com.