Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Change Decimal Mark in Dan Ebberts’s Counter Expression

  • Change Decimal Mark in Dan Ebberts’s Counter Expression

    Posted by Konstantin Fuchs on July 26, 2016 at 4:24 pm

    Hey folks,
    I’m using Dan Ebberts’s counter expression (https://www.motionscript.com/design-guide/counter.html), but I would want to change the mark in front of the decimals from “.” to “,” which is the german way of displaying decimal numbers.
    So for example 123456,789 instead of 123456.789
    AE is running in english, so probably this causes the issue. It would be great if there was a solution without changing the AE language or workaround with an extra layer for the decimals…

    I’m very thankful for any ideas!
    Konne

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

    Mil Malchiodi replied 6 years, 10 months ago 3 Members · 3 Replies
  • 3 Replies
  • Kalleheikki Kannisto

    July 26, 2016 at 6:47 pm

    Since you don’t need the dollar sign and the thousand separators, you could do this:

    numDecimals = 2;
    beginCount = -1999;
    endCount = 1999;
    dur = 4;

    t = time - inPoint;
    s = linear (t, 0, dur, beginCount, endCount).toFixed(numDecimals);
    s.replace(".",",")

  • Konstantin Fuchs

    July 27, 2016 at 8:39 am

    Hey Kalle, thanks for your quick response!

    your suggestions seems to do the trick, but as it turns out I need those seperators.
    For example 123.456,78 instead of 123,456.78.

    I tried to put “s.replace(“.” , “,”)” in the original expression, but could’t get it to work.

    Buuut after doing some further online research I stumbled over this sweet piece of expression, which I find pretty versitile and fits my needs perfectly.
    Credit goes to Sébastien Lavoie at https://keyframed.tv/how-to-format-a-slider-control-value-as-money-in-after-effects/

    Thanks anyways!

    spacer = " ";
    decimal = ".";
    prefix = "$";
    suffix = "¢";

    isPrefixed = (effect("Show prefix")("Checkbox") == 1 ? prefix : "");
    isSuffixed = (effect("Show suffix")("Checkbox") == 1 ? suffix : "");
    amount = effect("Amount")("Slider");

    function convertToMoney(amount) {
    var _sign, _prefix, _suffix;
    _sign = "";
    _prefix = ((isPrefixed) ? prefix : "");
    _suffix = ((isSuffixed) ? suffix : "");

    // Removing the negative
    if (amount < 0) {
    _sign = "-";
    amount = -amount;

    }

    amount = parseFloat(amount).toFixed(2);

    amount = amount.toString().replace(/./g, function(character, index, array) {
    if(character === ".") {
    return decimal;
    } else if ((array.length - index) % 3 || index === 0) {
    return character;
    } else {
    return spacer + character;
    }
    });

    return _sign + _prefix + amount + _suffix;
    }

    convertToMoney(amount);

  • Mil Malchiodi

    June 26, 2019 at 5:03 pm

    This is kind of an old post, but I got here with the same problem. I just fixed it.

    In line 26 of the expression ( the original from Dan), you have:
    outStr += “,” + s.substr(-i*3,3);

    Just replace the “,” with “.” and that would do the trick.

    For me, it ended like below (with no decimals, without dollar sign).
    Hopefully it will help someone else!

    numDecimals = 0;
    commas = true;
    dollarSign = false;
    beginCount = 100000;
    endCount = 174000;
    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;
    }

    -MiL-

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