Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Converting source text to a money format (eg: 603187 to $603,187)

  • Converting source text to a money format (eg: 603187 to $603,187)

    Posted by Ryan Fannon on April 15, 2008 at 3:23 pm

    Not sure if this is even possible, but I have a source text layer tied to a slider control. I would like to convert the source text from 603187 to a money format of $603,187.

    Any ideas?

    Ryan

    Jason Leaver replied 16 years, 6 months ago 3 Members · 3 Replies
  • 3 Replies
  • Mike Clasby

    April 15, 2008 at 4:02 pm

    If you put this Dan Ebberts expression on the Source Text, then mask off the two zeros to the right of the decimal, I think that’s got it. (Copy the expression, Alt-click the Source Text Stopwatch, Paste, click outside the box)

    numDecimals = 2;
    commas = true;
    dollarSign = true;
    beginCount = 603187;
    endCount = 603187;
    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;
    }

    His expression is very flexible and from here:

    https://www.motionscript.com/design-guide/counter.html

  • Ryan Fannon

    April 15, 2008 at 4:08 pm

    Cool. It works great.

    I replaced the beginCount and endCount numbers with a slider variable. I just pickwhipped the slider. Now the numbers can be animated and the format stays.

    Thanks

  • Jason Leaver

    January 17, 2010 at 7:22 pm

    This is really handy – but would be even greater is if a Slider Control could be used so the numbers could be controled by keyframe. I can’t for the life of me figure it out. I tried the following but I’m getting an error. An ideas?

    numDecimals = 2;
    commas = true;
    dollarSign = true;
    beginCount = -1999;
    endCount = 1999;
    dur = 4;

    t = time - inPoint;
    s = effect("Counter Control")("Slider").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;
    }

We use anonymous cookies to give you the best experience we can.
Our Privacy policy | GDPR Policy