Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Adding space after 3 numbers

  • Adding space after 3 numbers

    Posted by Remy Berden on August 24, 2016 at 10:20 am

    Hi, I’m working on a project where I need to display a number, with a space between numbers every 3 characters.

    So, for example:
    300
    30 000
    300 000
    300 000 000
    etc.

    Now I have to following code to add a comma to the numbers, if I try to replace ‘,’ with ‘ ‘ though, I get a syntax error. Any suggestions for workarounds?

    var toDisplay = comp("00_input").layer("cijfer_3_1")("Text")("Source Text").value;

    var num = toDisplay;
    num = Comma(num);
    [num]

    function Comma(number)
    {
    number = '' + Math.round(number);
    if (number.length > 3)
    {
    var mod = number.length % 3;
    var output = (mod > 0 ? (number.substring(0,mod)) : '');
    for (i=0 ; i < Math.floor(number.length / 3); i++)
    {
    if ((mod == 0) && (i == 0))
    output += number.substring(mod+ 3 * i, mod + 3 * i + 3);
    else
    output+= "," + number.substring(mod + 3 * i, mod + 3 * i + 3);
    }
    return (output);
    }
    else return number;
    }

    Kalleheikki Kannisto replied 9 years, 11 months ago 2 Members · 1 Reply
  • 1 Reply
  • Kalleheikki Kannisto

    August 24, 2016 at 1:30 pm

    That should work. The syntax error may be the &lt; instead of <

    Kalleheikki Kannisto
    Senior Graphic Designer

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