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: 2290
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:

Lightwrap in After Effects

Thumbnail for: Lightwrap in After Effects
This brief tutorial covers the compositing technique of light wrapping.
After Effects CS4
Keying
Video-/Tutorials

Views: 453
Permalink
posted by jamie on Jan 13, 2012

Lightwrap Preset

Thumbnail for: Lightwrap Preset
This is a preset that you can use on green screen footage or just general compositing.
After Effects CS5
Keying
Presets (ffx)

Views: 340
Permalink
posted by jamie on Jan 13, 2012

3D Cube Creator

Thumbnail for: 3D Cube Creator
This script is used to create a 3d cube. You can later replace the different sides and spin the null around for easy animation.
After Effects CS3
3D
Scripts (jsx)

Views: 2412
Permalink
posted by MicGyver on Nov 11, 2011


 

 

follow us on http://twitter.com/mgxchangeget in touch on facebook

 

 

motion graphics eXchange - Get The Search Engine