Highlighted

Rewrite expression for the new JS engine

New Here ,
Jun 06, 2020

Copy link to clipboard

Copied

Hi Everyone, 

I'm trying to re-write this expression so it will work with the new JS engine: 

This is the original expression: 

 

var num = effect("Slider Control")("Slider")*100;
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;
}

 

This is the modified version that I tried to fix:

 

var num = effect("Slider Control")("Slider")*100;
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;

}
}

 

 

What am I missing? 

 

Thanks,

TOPICS
Expressions

Views

122

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

Rewrite expression for the new JS engine

New Here ,
Jun 06, 2020

Copy link to clipboard

Copied

Hi Everyone, 

I'm trying to re-write this expression so it will work with the new JS engine: 

This is the original expression: 

 

var num = effect("Slider Control")("Slider")*100;
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;
}

 

This is the modified version that I tried to fix:

 

var num = effect("Slider Control")("Slider")*100;
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;

}
}

 

 

What am I missing? 

 

Thanks,

TOPICS
Expressions

Views

123

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Jun 06, 2020 0
HeladIL LATEST
New Here ,
Jun 07, 2020

Copy link to clipboard

Copied

I think I figured it out, 

I moved the function call to the bottom

 

var num = effect("Slider Control")("Slider")*100;


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;

}
}

num = Comma(num);
[num]

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jun 07, 2020 0