Skip to main content
Mooreah
Participant
March 1, 2016
Answered

Replace comma with dot in a text layer expression

  • March 1, 2016
  • 1 reply
  • 2302 views

Hi!

I need to do a simple counter from 0 to billions so i found this expression that works perfectly:

//begin code

startTime = 0; //seconds

endTime = 5; //seconds

beginCount = 0;

endCount = 9700698977;

hasCommas = true;

function addCommas ( s ){

if( s.length <= 3 )

return s;

else

return s.substring(0 , 3) + "," + addCommas(s.substring(3, s.length));

}

function reverse( s ){

newStr = "";

for(i = s.length-1; i >= 0; i--)

newStr += s.charAt(i)

return newStr;

}

val = Math.round (linear(time, startTime, endTime, beginCount, endCount) );

if( hasCommas )

reverse (addCommas(reverse( val + "" )))

else

val

//end code

The problem is that i need to change the commas with dots to look like 9.700.698.977, anyone know how to do it?

This topic has been closed for replies.
Correct answer Dan Ebberts

Just change this line:

return s.substring(0 , 3) + "," + addCommas(s.substring(3, s.length));

to this:

return s.substring(0 , 3) + "." + addCommas(s.substring(3, s.length));

Dan

1 reply

Dan Ebberts
Community Expert
Dan EbbertsCommunity ExpertCorrect answer
Community Expert
March 1, 2016

Just change this line:

return s.substring(0 , 3) + "," + addCommas(s.substring(3, s.length));

to this:

return s.substring(0 , 3) + "." + addCommas(s.substring(3, s.length));

Dan

Mooreah
MooreahAuthor
Participant
March 1, 2016

Thank you very much!