Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Need help in moving the comma

  • Need help in moving the comma

    Posted by Avinash Ramanath on February 1, 2021 at 6:18 pm

    Hi, I came across this incredible number counter, I need help in moving the comma one place left. For example, currently, it’s like this 400,00. I want it to be 40,000.

    numDecimals = 0;

    commas = true;

    dollarSign = false;

    beginCount = 500;

    endCount = 40000;

    dur = 2;

    t = time - inPoint;

    s = ease (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;


    prefix + s;


    Kevin Camp replied 3 years ago 3 Members · 4 Replies
  • 4 Replies
  • Trent Armstrong

    February 1, 2021 at 6:42 pm


    The expression is adding a “+” to the end of the number and therefore putting the comma in the wrong spot.

    Try this line instead:

    s = ease (t, 0, dur, beginCount, endCount).toFixed(numDecimals);

    And let me know if that’s just not what you’re looking for.


  • Avinash Ramanath

    February 16, 2021 at 12:05 pm

    Hi Trent, thanks for your reply and direction.

    I found a better way and shorter of doing it. Leaving the code here for someone who might find it useful,

    Thanks to Nick Khoo’s video –

    Apply point control effect to the text layer and paste the below expression to sourceText param.

    s = "" + Math.round(effect("Point Control")("Point")[0]);
    "INR " + s.replace(/\B(?=(?:(\d\d)+(\d)(?!\d))+(?!\d))/g, ',') + "+";

    //use this for numbers with decimals

    s = "" + Math.round(effect("Point Control")("Point")[0]);
    "INR " + s.replace(/\B(?=(?:(\d\d)+(\d)(?!\d))+(?!\d))/g, ',') + "+";

    Some contents or functionalities here are not available due to your cookie preferences!

    This happens because the functionality/content marked as “Google Youtube” uses cookies that you choosed to keep disabled. In order to view this content or use this functionality, please enable cookies: click here to open your cookie preferences.

  • Trent Armstrong

    February 16, 2021 at 1:53 pm

    REGEX! Right on! This is a great look at how regex can be used in expressions!


  • Kevin Camp

    February 16, 2021 at 5:06 pm

    Also, if you have a newer version of AE (17+) and set the Expression Engine to JavaScript in the Project Settings, you can use the java function toLocaleString() to add commas/separators based on language and country.

    This would put in commas as separators:

    num = effect("Point Control")("Point")[0] ;

    num.toLocaleString('en-US') ;

    This would use spaces for French:

    num = effect("Point Control")("Point")[0] ;

    num.toLocaleString('fr-FR') ;

    You can use a slider or rotation control or even the sourceText value, but you’ll need to convert it to float or integer first:

    num = effect("Slider Control")("Slider") ;

    parseFloat(num).toLocaleString() ;

    There are also options for currency and date and more in toLocaleString(). This link has some examples:

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