motion graphics eXchange
top

Universal Counter/Currency Formatter

Thumbnail for: Universal Counter/Currency Formatter
Create a universal counter that will count from one value to another over a fixed amount of time. Easily format the count with commas, add a dollar sign for currency formatting, and specify the number of digits to the right of the decimal point.
After Effects CS3
Text-FX
Expressions

Views: 11718
Permalink
visit |  share this  error? 
"This is a perfect application for an expression applied to the source text parameter of a text layer. We'll drive the counter with AE's linear() interpolation method. This allows us (with a single line of code) to easily map the counting range across the duration of the count.

As a bonus, doing it this way will automatically give us a counter that will count up or down. All we have to do to make it count down is make the beginning count larger than the ending count. Also, this method will automatically cause the output to freeze when it reaches the end count.

For the formatting, we can take advantage of a couple of JavaScript's built in methods to help us accomplish our goal. We'll use the string method substr() to do the manipulation necessary to insert the commas and toFixed() to handle the formatting of the decimals. For negative numbers, we'll strip off the sign prior to formatting and re-apply it afterwards, along with an optional dollar sign.

The code may take you a while to decipher, but for most applications you should be able to just paste it into your project and modify the six variables at the beginning of the code."
numDecimals = 2;
commas = true;
dollarSign = true;
beginCount = -1999;
endCount = 1999;
dur = 4;

t = time - inPoint;
s = linear (t, 0, dur, beginCount, endCount).toFixed(numDecimals);
 
prefix = "";
if (s[0] == "-"){
  prefix = "-";
  s = s.substr(1);
}
if(dollarSign) 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);
  }
  prefix + outStr + decimals;
}else{
  prefix + s;
}
by Dan Ebbert

Keywords

Expression, Text, Count, Countdown

(Min. Version: After Effects CS3, Category: Text-FX, Type: Expressions)
posted by MicGyver on Jan 18, 2010

 

Related topics:

CountdownTimer Preset

Thumbnail for: CountdownTimer Preset
The CountdownTimer preset uses expressions to make it easier for you to create countdowns.
After Effects CS4
Useful things
Presets (ffx)

Views: 25426
Permalink
posted by Trent Armstrong on Oct 15, 2010

Text Counter over time

Thumbnail for: Text Counter over time
This expression will count from 0 to 100 over a 4-second interval.
After Effects CS3
Text-FX
Expressions

Views: 31763
Permalink
posted by MaxX on Feb 22, 2010

Clockworks Preset/Custom Effect

Thumbnail for: Clockworks Preset/Custom Effect
With this Preset, you can create Clocks, or countdowns. You can add Time, with fully functional switches and parameters!
After Effects CS3
Text-FX
Presets (ffx)

Views: 9792
Permalink
posted by MaxX on Feb 02, 2010


 

 

follow us on http://twitter.com/mgxchangegoogle+get in touch on facebook

 

 

Full length video training series presented by motion graphics industry professionals. Click here to visit Motionworks website!