Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Number countdown with separation at every thousand units

  • Number countdown with separation at every thousand units

    Posted by Carlos Leite on May 20, 2016 at 2:15 am

    Hello everyone!

    I need to make a countdown going from 0 to 13.800.

    Going from 0 to 13800 is no issue whatsoever; where I work, however, they require to separate with a dot or a comma for every unit of thousands: 2.000, 10.000, 1.500.000, and so on.

    Would like some suggestions on how to do that, if you will.
    If there’s already another thread about it, please post it (I couldn’t find it). Thank you in advance! Cheers

    Xavier Gomez replied 10 years, 2 months ago 2 Members · 5 Replies
  • 5 Replies
  • Xavier Gomez

    May 20, 2016 at 10:00 am

    There are many many threads on counters on this forum, so many that it’s hard to find the right one…

    The following should work:

    // provide number to format. For instance:
    tStart = inPoint;
    tEnd = inPoint + 5;
    vStart = 0;
    vEnd = 13800;
    x = linear(time, tStart, tEnd, vStart, vEnd);

    // transform number to a string with 0 decimals
    x = x.toFixed(0);

    // provide separator
    separator = ",";

    // final result:
    x.replace(/(\d)(?=(\d{3})+(?!\d))/g, "$1"+separator);

    Xavier

  • Carlos Leite

    May 20, 2016 at 8:17 pm

    Worked perfectly! Is there a thread where I can learn more about what the last line does?

    Again, thank you very much!

  • Xavier Gomez

    May 21, 2016 at 10:35 am

    The last line modifies the original string using a regular expression.

    Regular expressions can be from very simple to fairly complicated, and not worth the effort to learn if you plan to use very occasionnaly. Most of the time you’ll find the regular expression suited to your needs with a quick search at https://stackoverflow.com/ (in the serach, specify RegExp + javascript + what you want).

    It’s actually possible to do what you wanted without a RegExp, the code is just longer but in the end it’s the same. See for instance this thread: https://forums.creativecow.net/thread/227/21144#21144 (the part that modifies the thousands is under if (commas){…}).

    Xavier

  • Xavier Gomez

    May 21, 2016 at 10:41 am

    The last line modifies the original string using a regular expression.

    Regular expressions can be from very simple to fairly complicated, and not worth the effort to learn if you plan to use very occasionnaly. Most of the time you’ll find the regular expression suited to your needs with a quick search at https://stackoverflow.com/ (in the search, specify RegExp + javascript + what you want).

    It’s actually possible to do what you wanted without a RegExp, the code is just longer but in the end the result is the same. See for instance this thread: https://forums.creativecow.net/thread/227/21144#21144 (the part that modifies the thousands is under if (commas){…}).

    Xavier

  • Xavier Gomez

    May 21, 2016 at 10:44 am

    Hmmm, i tried to edit because in the first post the link to stackoverflow didnt work… Strange result.

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