ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

Number countdown with separation at every thousand units

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Carlos Leite
Number countdown with separation at every thousand units
on May 20, 2016 at 2:15:06 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


Return to posts index

Xavier Gomez
Re: Number countdown with separation at every thousand units
on May 20, 2016 at 10:00:40 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


Return to posts index

Carlos Leite
Re: Number countdown with separation at every thousand units
on May 20, 2016 at 8:17:22 pm

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

Again, thank you very much!


Return to posts index


Xavier Gomez
Re: Number countdown with separation at every thousand units
on May 21, 2016 at 10:35:50 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 http://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


Return to posts index

Xavier Gomez
Re: Number countdown with separation at every thousand units
on May 21, 2016 at 10:41:17 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 http://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


Return to posts index

Xavier Gomez
Re: Number countdown with separation at every thousand units
on May 21, 2016 at 10:44:29 am

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


Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2018 CreativeCOW.net All Rights Reserved
[TOP]