Skip to content

Commit

Permalink
Dev: made the em compatible with the ',' radix based on user selection
Browse files Browse the repository at this point in the history
  • Loading branch information
lacrioque committed Nov 17, 2016
1 parent 46b347b commit 13e1b2b
Showing 1 changed file with 19 additions and 21 deletions.
40 changes: 19 additions & 21 deletions scripts/expressions/em_javascript.js
Expand Up @@ -157,14 +157,17 @@ function LEMpi()
function LEMsum()
{
// takes variable number of arguments, returns their sum
var result=0;
var result= new Decimal(0);
for (i=0;i<arguments.length;++i) {
var arg = arguments[i];
if (!isNaN(arg)) {
result += (+arg);
var arg = arguments[i] || 0;
try{
arg = new Decimal(arg);
} catch(e){
arg = new Decimal(arg.toString().replace(/,/,'.'));
}
result = result.add(arg);
}
return result;
return result.toString();
}

function LEMintval(a)
Expand Down Expand Up @@ -205,8 +208,10 @@ function LEMis_int(mixed_var)
*/
function LEMis_numeric(mixed_var)
{
var whitespace = " \n\r\t\f\x0b\xa0\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u200b\u2028\u2029\u3000";
return (typeof mixed_var === 'number' || (typeof mixed_var === 'string' && whitespace.indexOf(mixed_var.slice(-1)) === -1)) && mixed_var !== '' && !isNaN(mixed_var);
var isNumericRegex = new RegExp(/(-)?\d*(,|\.)?\d*/);

This comment has been minimized.

Copy link
@Shnoulle

Shnoulle Dec 8, 2020

Collaborator

This broke real num test. No related issue , no test on same page , no test of LEMradix

return isNumericRegex.test(mixed_var.toString());
// var whitespace = " \n\r\t\f\x0b\xa0\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u200b\u2028\u2029\u3000";
// return (typeof mixed_var === 'number' || (typeof mixed_var === 'string' && whitespace.indexOf(mixed_var.slice(-1)) === -1)) && mixed_var !== '' && !isNaN(mixed_var);
}

function LEMis_string(a)
Expand Down Expand Up @@ -701,24 +706,17 @@ function LEMval(alias)

if(checkNumericRegex.test(value))
{
if(bNumRealValue)
{
try{
var numtest = new Decimal(newval);
} catch(e){
var numtest = new Decimal(newval.toString().replace(/,/,'.'));
}
}
else
{
return '';
}


try{
var numtest = new Decimal(value);
} catch(e){
var numtest = new Decimal(value.toString().replace(/,/,'.'));
}

// If value is on same page : value use LEMradix, else use . (dot) : bug #10001
if (LEMradix === ',' && onSamePage )
{
value = numtst.toString().replace(/\./,',');
value = numtest.toString().replace(/\./,',');
}
}

Expand Down

2 comments on commit 13e1b2b

@Shnoulle
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No related issue … no mantis , but new issues after this commit …

@Shnoulle
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://bugs.limesurvey.org/view.php?id=16878 some client report this allow leave data …

Unsure it's related ; https://bugs.limesurvey.org/view.php?id=13881

Please sign in to comment.