Skip to main content
dzweigel
Participant
February 14, 2023
Answered

Need Help to Add Comma in expression

  • February 14, 2023
  • 1 reply
  • 493 views

Hi all...I am using an old template and have no exprience in writing expressions. I just want to know how to and a comma to the output. Here is the script...

 

numDecimals = 0; beginCount = 50; endCount =105515; dur =0.7; t = time - inPoint; s = linear (t, 0, dur, beginCount, endCount).toFixed(numDecimals); prefix = ""; if (s[0] == "-"){ prefix = "-"; if (numDecimals > 0){ decimals = s.substr(-(numDecimals + 1)); s = s.substr(0,s.length - (numDecimals + 1)); } outStr = s.substr(-s.length, (s.length-1)%3 +1); for (i = Math.floor((s.length-1)/3); i > 0; i--){ outStr += "," + s.substr(-i*3,3); } prefix + outStr + decimals; }else{ prefix + s; }

 

Any help would be great.

 

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

Try this version:

numDecimals = 0;
commas = true;
dollarSign = false;
beginCount = 50;
endCount = 105515;
dur = 0.7;

t = time - inPoint;
s = linear (t, 0, dur, beginCount, endCount).toFixed(numDecimals);
 
prefix = "";
if (s[0] == "-"){
  prefix = "-";
  s = s.substr(1);
}
if(dollarSign) prefix += "$";
 
if (commas){
  decimals = "";
  if (numDecimals > 0){
    decimals = s.substr(-(numDecimals + 1));
    s = s.substr(0,s.length - (numDecimals + 1));
  }
  outStr = s.substr(-s.length, (s.length-1)%3 +1);
  for (i = Math.floor((s.length-1)/3); i > 0; i--){
    outStr += "," + s.substr(-i*3,3);
  }
  prefix + outStr + decimals;
}else{
  prefix + s;
}

1 reply

Dan Ebberts
Community Expert
Dan EbbertsCommunity ExpertCorrect answer
Community Expert
February 14, 2023

Try this version:

numDecimals = 0;
commas = true;
dollarSign = false;
beginCount = 50;
endCount = 105515;
dur = 0.7;

t = time - inPoint;
s = linear (t, 0, dur, beginCount, endCount).toFixed(numDecimals);
 
prefix = "";
if (s[0] == "-"){
  prefix = "-";
  s = s.substr(1);
}
if(dollarSign) prefix += "$";
 
if (commas){
  decimals = "";
  if (numDecimals > 0){
    decimals = s.substr(-(numDecimals + 1));
    s = s.substr(0,s.length - (numDecimals + 1));
  }
  outStr = s.substr(-s.length, (s.length-1)%3 +1);
  for (i = Math.floor((s.length-1)/3); i > 0; i--){
    outStr += "," + s.substr(-i*3,3);
  }
  prefix + outStr + decimals;
}else{
  prefix + s;
}
dzweigel
dzweigelAuthor
Participant
February 15, 2023

Thank you such much. Designing, yes. Coding, nope.