Skip to content

Commit

Permalink
Fixed issue #11740: Decimal throwerreor with negative value
Browse files Browse the repository at this point in the history
Dev: Put a try everywhere using Decimal(value), unsure we need it everywhere
  • Loading branch information
Shnoulle committed Oct 15, 2016
1 parent 84c13e7 commit 33a1dd4
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 14 deletions.
8 changes: 4 additions & 4 deletions scripts/array-totalsum.js
Expand Up @@ -40,9 +40,9 @@ function updatetotals()
// First get number of columns (only visible and enabled inputs)
var iColumnNum=$('#'+sTableID+' tbody tr:first-child input:enabled:visible').length;
//Get An array of jQuery Objects
var $iRow = sTable.find('tr');
var $iRow = sTable.find('tr');
//Iterate through the columns
for (var i = 1; i <= iColumnNum; i++)
for (var i = 1; i <= iColumnNum; i++)
{
var sum = new Decimal(0);
$iRow.each(function(){
Expand All @@ -60,7 +60,7 @@ function updatetotals()
}
function formatValue(sValue)
{

sValue=Number(sValue).toString();
var sRadix=LSvar.sLEMradix;
sValue=sValue.replace('.',sRadix);
Expand All @@ -78,7 +78,7 @@ function normalizeValue(aValue)
try {
outNumber = new Decimal(aValue);
} catch(e){}

if(outNumber == false)
{
var numReplaced = aValue.toString().replace(/,/g, ".");
Expand Down
34 changes: 24 additions & 10 deletions scripts/expressions/em_javascript.js
Expand Up @@ -591,11 +591,12 @@ function LEMval(alias)
case 'I': //Language Question
case '|': //File Upload
case 'X': //BOILERPLATE QUESTION
var numtest = new Decimal(value);
if(!numtest.isNaN()){
try {
var numtest = new Decimal(value);
return parseFloat(numtest.valueOf());
} else {
shown = value; // what about "no answer"?
}
catch(e) {
shown = value;

This comment has been minimized.

Copy link
@Shnoulle

Shnoulle Oct 15, 2016

Author Collaborator

I don't understand : why we set shown to value and return like the other ?

}
break;
case 'M': //Multiple choice checkbox
Expand All @@ -605,11 +606,12 @@ function LEMval(alias)
}
else {
if (attr.type == 'P' && varName.match(/comment$/)) {
var numtest = new Decimal(value);
if(!numtest.isNaN()){
try {
var numtest = new Decimal(value);
shown = parseFloat(numtest.valueOf());
} else {
shown = value; // what about "no answer"?
}
catch(e) {
shown = value;
}
}
else {
Expand Down Expand Up @@ -713,7 +715,13 @@ function LEMval(alias)
{
if(bNumRealValue)
{
return parseFloat(new Decimal(value).valueOf());
try {
var numtest = new Decimal(value);
return parseFloat(numtest.valueOf());
}
catch(e) {
return value;
}
}
else
{
Expand All @@ -728,7 +736,13 @@ function LEMval(alias)
// if (newval != parseFloat(newval)) {
// return '';
// }
return parseFloat(new Decimal(newval).valueOf());
try {
var numtest = new Decimal(value);
return parseFloat(numtest.valueOf());
}
catch(e) {
return value;
}
}

// convert content in date questions to standard format yy-mm-dd to facilitate use in EM (comparisons, min/max etc.)
Expand Down

0 comments on commit 33a1dd4

Please sign in to comment.