ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

Re: Numbers Expression Replace commas with a space....

COW Forums : Adobe After Effects Expressions

FAQ   •   VIEW ALL   •   ADD A NEW POST   •   PRINT
Respond to this post   •   Return to posts index   •   Read entire thread


Declan Smith
Re: Numbers Expression Replace commas with a space....
on Jan 22, 2015 at 5:32:35 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
http://www.madpanic.tv
After Effects CS6/ FCS3 / Canon XLH1 / Canon 7D / Reason / Cubase

"it's either binary or it's not"


Posts IndexRead Thread 


Current Message Thread:





© 2019 CreativeCOW.net All Rights Reserved
[TOP]