Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions How to add “.” or “,” in a number inside a text layer

  • How to add “.” or “,” in a number inside a text layer

    Posted by Lord Scales on May 28, 2007 at 4:08 pm

    Hi there! What I wanna do is for example to make 8000 become 8.000 inside a text layer. Or 58123645 become 58.123.645 (in Brazil, we use “.”, maybe in USA or other countries “,” is used, but anyway…).

    I have this in my Source Text (similar to Universal Counter tutorial, from Dan https://www.motionscript.com/design-guide/counter.html):

    vMin = 0; //minimum value
    vMax = 58123645; //maximum value
    dur = 11; //duration
    d = 0; //number of decimals

    linear (time, inPoint, dur, vMin, vMax).toFixed(d)

    But the problem is that there are no “.” (or “,”) added in each 3 numbers. I tried tried tried and I could not find a way to add “.” automatically.

    Could anyone help me?

    Thaks a lot!

    Lord Scales replied 18 years, 11 months ago 2 Members · 5 Replies
  • 5 Replies
  • Filip Vandueren

    May 28, 2007 at 4:51 pm

    Here’s a discussion we had a few months ago:

    https://forums.creativecow.net/cgi-bin/new_read_thread.cgi?forumid=2&postid=880630&univpostid=880128

    use the final expression, but read all of it, there’s some interesting stuff about the limitation of slider-controls for high numbers

  • Lord Scales

    May 28, 2007 at 7:53 pm

    Hmm, nice. My friend gave me something I never saw before:

    function addPoint(numTxt) {
    numTxt = String(numTxt);
    regEx = /^(.*\s)?([+-]?\d+)(\d{3}\b)/;
    return numTxt == (numTxt = numTxt.replace(regEx, “$1$2,$3”)) ? numTxt : addPoint(numTxt);
    }

    This worked fine to do what I wanted, but I almost died when I saw that.
    It works like this, in a source text:

    function addPoint(numTxt) {
    numTxt = String(numTxt);
    regEx = /^(.*\s)?([+-]?\d+)(\d{3}\b)/;
    return numTxt == (numTxt = numTxt.replace(regEx, “$1$2,$3”)) ? numTxt : addPoint(numTxt);
    }

    addPoint (56448646455646848668)

    You are done!

  • Filip Vandueren

    May 28, 2007 at 8:29 pm

    Nice !

    Clever stuff using regexp…
    And I like the recursion going on in the return statement: have to add that to my bag of tricks.

  • Lord Scales

    May 28, 2007 at 8:37 pm

    Do you know any place in the Internet with info or even tutorials about this?

  • Lord Scales

    May 29, 2007 at 2:51 pm

    Looking in Google, I found this nice site: https://www.regular-expressions.info/

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