Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Numbers Expression Replace commas with a space….

  • Numbers Expression Replace commas with a space….

    Posted by Ross Hammond on January 22, 2015 at 4:07 pm

    Hey folks see below is an expression I have for a counter which works perfectly, However I would like to replace the commas with a space if possible as this is a request for reversioning into a different language can someone point me in the direction of how to do this,

    would it be in the commas not requested section…..

    Thank you so much.

    Regards Chossy.

    num = thisComp.layer("Controls").effect("number")("Slider")*100000;
    amtOfDec = thisComp.layer("Controls").effect("amt_of_decimals")("Slider");
    commas = thisComp.layer("Controls").effect("use_commas")("Checkbox");
    //--
    num = num + 0;
    amtOfDec = amtOfDec + 0;
    commas = commas == 1;

    //--
    if(! commas){

    //commas not requested
    num.toFixed( amtOfDec );

    }else{

    //commas requested

    //This function takes a positive whole number as a string
    //and adds commas to it

    function addCommas( str ){
    finalResult = "";
    for( i = str.length - 1; i >= 0; i-- ){
    finalResult = str.charAt( i ) + finalResult;
    if( (str.length - i) % 3 == 0 && i != 0 )
    finalResult = "," + finalResult;
    }
    return finalResult;
    }

    //--

    intPart = Math.floor( Math.abs( num ) );
    decPart = Math.abs(num) - intPart;
    wasNeg = num < 0;
    result = "";
    if( wasNeg )
    result = "–" + result;
    intPartString = intPart + "";
    decPartString = decPart.toFixed( amtOfDec ) + "";
    decPartString = decPartString.substring( 1 );
    result = result + addCommas( intPartString ) + decPartString;
    result
    }

    The last true family man

    Ross Hammond replied 11 years, 3 months ago 3 Members · 3 Replies
  • 3 Replies
  • Dan Ebberts

    January 22, 2015 at 5:18 pm

    I haven’t tried it, but I think you could just replace this line:

    finalResult = “,” + finalResult;

    with this:

    finalResult = ” ” + finalResult;

    Dan

  • Declan Smith

    January 22, 2015 at 5:32 pm

    You just need to change the line:

    finalResult = ‘,’ + finalResult;

    to

    finalResult = ‘ ‘ + finalResult;

    Or you could make this more configurable by having another slider to control what separator character you want and using the changes as in the script below, Basically the two lines with the word ‘separator’ in is what you need.

    To use this, just put the slider to the ascii code of the required character (don’t go over 255!). For a space, put the slider at 32 and for a comma 44.

    num = thisComp.layer("Controls").effect("number")("Slider")*100000;
    amtOfDec = thisComp.layer("Controls").effect("amt_of_decimals")("Slider");
    commas = thisComp.layer("Controls").effect("use_commas")("Checkbox");
    separator = String.fromCharCode(Math.ceil(thisComp.layer("Controls").effect("separator")("Slider")));
    //--
    num = num + 0;
    amtOfDec = amtOfDec + 0;
    commas = commas == 1;

    //--
    if(! commas){

    //commas not requested
    num.toFixed( amtOfDec );

    }else{

    //commas requested

    //This function takes a positive whole number as a string
    //and adds commas to it

    function addCommas( str ){
    finalResult = "";
    for( i = str.length - 1; i >= 0; i-- ){
    finalResult = str.charAt( i ) + finalResult;
    if( (str.length - i) % 3 == 0 && i != 0 )
    finalResult = separator + finalResult;
    }
    return finalResult;
    }

    //--

    intPart = Math.floor( Math.abs( num ) );
    decPart = Math.abs(num) - intPart;
    wasNeg = num < 0;
    result = "";
    if( wasNeg )
    result = "–" + result;
    intPartString = intPart + "";
    decPartString = decPart.toFixed( amtOfDec ) + "";
    decPartString = decPartString.substring( 1 );
    result = result + addCommas( intPartString ) + decPartString;
    result
    }

    Declan Smith
    https://www.madpanic.tv
    After Effects CS6/ FCS3 / Canon XLH1 / Canon 7D / Reason / Cubase

    “it’s either binary or it’s not”

  • Ross Hammond

    January 22, 2015 at 11:04 pm

    Thank you very much for the responses, looks pretty straightforward. I’ll give it a go tomorrow at work.

    Thank you so much guys.

    Regards Ross.

    The last true family man

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