Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Creating an animated counter for money

  • Creating an animated counter for money

    Posted by Peter Butler on March 30, 2016 at 9:45 am

    Hi everyone.

    I found a great tutorial on here that allows me to type in a figure and the counter will animate up to that amount. The issue is that the last three digits in the counter are separated by a decimal point not by a comma. I need all the separations to be commas as they would be if writing a currency figure.

    I’ve attached to screen shots to show you what it’s doing. If you look at the first screen shot you can see that the last three figure are separated by a decimal point not a comma like they are in the other segments. How do I change the expression so that all the separations are commas?

    Would very much appreciate someones help on this.

    Many thanks in advance,

    Peter

    numDecimals = 3
    ;
    commas = true;
    dollarSign = false;

    beginCount = -0;
    endCount = 1000000000000000;

    dur = 15

    ;

    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;
    }

    Peter Butler replied 10 years, 4 months ago 2 Members · 7 Replies
  • 7 Replies
  • Declan Smith

    March 30, 2016 at 10:54 am

    If what you are trying to achieve is to remove the .000, just change the variable
    numDecimals =0

    I have simplified the commas section below also.

    numDecimals = 0;
    commas = true;
    dollarSign = false;
    beginCount = -0;
    endCount = 1000000000000000;
    dur = 15;
    t = time - inPoint;
    s = linear (t, 0, dur, beginCount, endCount).toFixed(numDecimals);

    prefix = "";
    if (s[0] == "-"){
    prefix = "-";
    s = s.substr(1);
    }
    if (commas) s = s.replace(/(\d)(?=(\d{3})+(?!\d))/g, "$1,");
    if(dollarSign) s = "$" + s;
    s;

    Declan Smith
    https://www.madpanic.tv
    After Effects CS6/ FCS3 / Canon XLH1 / Canon 7D / Reason / Cubase

    \”it\’s either binary or it\’s not\”

  • Peter Butler

    March 30, 2016 at 11:00 am

    Hi Declan,

    Thank you so much for this, I’ll try it out in a bit and let you know how I got on.

    Many thanks,

    Peter

  • Peter Butler

    March 30, 2016 at 12:45 pm

    Works perfectly, thank you so much. You’ve saved me a lot of time.

  • Peter Butler

    March 30, 2016 at 12:51 pm

    Actually just realised there’s still a decimal in there, it’s just moved inwards a bit.

    Any ideas?

    Peter

  • Declan Smith

    March 30, 2016 at 1:10 pm

    Try this:

    numDecimals = 0;
    commas = true;
    dollarSign = false;
    beginCount = -0;
    endCount = 1000000000000000;
    dur = 15;
    t = time - inPoint;
    s = linear (t, 0, dur, beginCount, endCount);
    if (numDecimals) {
    s = s.toFixed(numDecimals);
    } else {
    s = '' + s;
    }

    prefix = "";
    if (s[0] == "-"){
    prefix = "-";
    s = s.substr(1);
    }
    if (commas) s = s.replace(/(\d)(?=(\d{3})+(?!\d))/g, "$1,");
    if(dollarSign) s = "$" + s;
    s;

    Declan Smith
    https://www.madpanic.tv
    After Effects CS6/ FCS3 / Canon XLH1 / Canon 7D / Reason / Cubase

    \”it\’s either binary or it\’s not\”

  • Declan Smith

    March 30, 2016 at 2:04 pm

    Try this.

    numDecimals = 0;
    commas = true;
    dollarSign = false;
    beginCount = -0;
    endCount = 1000000000000000;
    dur = 15;
    t = time - inPoint;
    s = linear (t, 0, dur, beginCount, endCount);
    if (numDecimals) {
    s = s.toFixed(numDecimals);
    } else {
    s = '' + s;
    }

    prefix = "";
    if (s[0] == "-"){
    prefix = "-";
    s = s.substr(1);
    }
    if (commas) s = s.replace(/(\d)(?=(\d{3})+(?!\d))/g, "$1,");
    if(dollarSign) s = "$" + s;
    s;

    Declan Smith
    https://www.madpanic.tv
    After Effects CS6/ FCS3 / Canon XLH1 / Canon 7D / Reason / Cubase

    \”it\’s either binary or it\’s not\”

  • Peter Butler

    March 30, 2016 at 2:17 pm

    Now it’s perfect 🙂

    Again many thanks.

    Peter

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