motion graphics eXchange
top

Formatting a number with commas

Thumbnail for: Formatting a number with commas
Formatting a number with commas
After Effects 6
Text-FX
Expressions

Views: 25571
Permalink
visit |  share this  error? 
1. Create a comp. Name it anything you like.
2. Create a new text layer and name it "dummy" (this layer can be turned off; it feeds a number to the final text layer. I haven't found a way around this; please let me know if there's another way).
3. Add a slider to the "dummy" layer (Effects > Expression Controls > Slider Control). After Effects should automatically name the slider control "Slider"
4. Add an expression to Source Text of "dummy" (Animation > Add Expression).
5. Pickwhip the expression to the "Slider" control from step 3.
6. Create a second text layer. This will be the layer that displays the formatted number.
7. Add an expression to Source Text of the new text layer. Replace the code with the following:
 var num = thisComp.layer("dummy").text.sourceText;
 num = Comma(num);
 [num]
 
 function Comma(number)
    {
    number = '' + Math.round(number);
    if (number.length > 3)
       {
       var mod = number.length % 3;
       var output = (mod > 0 ? (number.substring(0,mod)) : '');
       for (i=0 ; i < Math.floor(number.length / 3); i++)
           {
           if ((mod == 0) && (i == 0))
                output += number.substring(mod+ 3 * i, mod + 3 * i + 3);
           else
                output+= ',' + number.substring(mod + 3 * i, mod + 3 * i + 3);
           }
       return (output);
       }
    else return number;
    }
Now try changing the value of the "Slider" control. Your visible text layer should reflect that number, now formatted with commas. Two catches: it only works for integers, and the slider tops out at 1,000,000. You should be able to pickwhip to any propery that contains a number (decimals are rounded off automatically).


(Min. Version: After Effects 6, Category: Text-FX, Type: Expressions)
posted by MicGyver on Sep 15, 2008

 

Related topics:

Folding Template

Thumbnail for: Folding Template
folding and unfolding template free to use.
Require After Effects CS6
After Effects CS6
Other
Projects (aep)

Views: 34584
Permalink
posted by fsimoni on Nov 05, 2012

Product, Service or App Promotion

Thumbnail for: Product, Service or App Promotion
After Effects Template. Promote your app, product or service
After Effects CS5
Useful things
Projects (aep)

Views: 16563
Permalink
posted by RedSpikeFx on Oct 30, 2012

Clean Logo V2

Thumbnail for: Clean Logo V2
After Effects CS4,CS5,CS5.5 and CS6 template logo reveal
After Effects CS4
Other
Projects (aep)

Views: 20778
Permalink
posted by aedaddy on Aug 19, 2012


 

 

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!