:: Forum >> Version 2 >>

Cell Algorithm Returning Nan??

Why does this Algorithm return "Nan" when mathematically it should return Zero?

The below grid is set out as follows: -


Col1 = Value to be deducted from Col2
Col2 = The Value to deduct
Col3 = The Starting Value


Enter 100.00 into row1 col1
Enter 114.17 into row2 col1

Col2 returns Nan when it should return Zero??

Please advice


var myData = [["0.00","214.17","214.17"],["0.00","0.00","0.00"]];
    
        
var 
str = new AW.Formats.String
var 
num = new AW.Formats.Number
var 
html = new AW.Formats.HTML
num.setTextFormat('####.##');
        

// grid control
var obj = new AW.UI.Grid;
obj.setCellData(myData);
obj.setCellFormat([htmlnumnumnumnum]);
obj.setColumnCount(3);
obj.setRowCount(2);
obj.setCellEditable(true); 
document.write(obj); 
    

obj.onCellValueChanged = function(valuecolrow){
  function 
rowByrow(colrow) {
    if (
row == 0) { var evaluate obj.getCellValue(20) - obj.getCellValue(00);
        
//alert(obj.getCellValue(0, 0));
        //alert(obj.getCellValue(2, 0));
        //alert(evaluate);
        
if (evaluate<0)  {alert('WARNING! 1The amount you have entered is incorrect and would take the balance less then zero or over the total nett value of the invoice'); }
         else 
        {
        return 
obj.getCellValue(20) - obj.getCellValue(00);
        }
    }
    else
    {
    var 
evaluate obj.getCellValue(2row 1) - obj.getCellValue(0row);
     if (
evaluate<0)  {alert('WARNING! 2The amount you have entered is incorrect and would take the balance less then zero or over the total nett value of the invoice'); }
        else
        {
        return 
obj.getCellValue(2row) - obj.getCellValue(0row) + obj.getCellValue(colrow 1
    }
    }
}
if (
col==0) {obj.setCellData(rowByrow,1,row);}
}
 
Jez (True Track Software)
Tuesday, October 26, 2010
Jez,
evaluate is a javascript reserved word (command),
Try defining a different name for that variable.
C++
Tuesday, October 26, 2010
Sorry that didn't work...

Here is a simpler version of the function with an Alert so I can see what it evaluates too

The Nan = -1.4210854715202004e-14 ????????????

obj.onCellValueChanged = function(valuecolrow){
                function 
rowByrow(colrow) {
                        if (
row == 0)
                        return 
obj.getCellValue(20) - obj.getCellValue(00)
                        else
                        return 
obj.getCellValue(2row) - obj.getCellValue(0row) + obj.getCellValue(colrow 1
                     }
            
alert(obj.getCellValue(2row) - obj.getCellValue(0row) + obj.getCellValue(colrow 1));          
            if (
col==0) {obj.setCellData(rowByrow,1,row);}
            }
 
Jez (True Track Software)
Tuesday, October 26, 2010
Not a Number (NaN) often occurs when a number is treated as a string.
perhaps parsing would work.

return parsefloat(obj.getCellValue(2, row)) - parsefloat(obj.getCellValue(0, row)) + parsefloat(obj.getCellValue(col, row - 1))

Incidentally
-1.4210854715202004e-14 means -1.42*** x 1/100 000 000 000 000
Hazzer
Wednesday, October 27, 2010
Thanks H,

I tried parseFloat, which I thought would deal with it.. but in the end I had to load the values into a variable and return them with the javascript functions toFixed

var count multi.getCellValue(5row) - multi.getCellValue(2row) + multi.getCellValue(colrow 1
return 
count.toFixed(2);
 
Incidentally that should be Hazzer (True Track Software) :)
Jez (True Track Software)
Wednesday, October 27, 2010



This topic is archived.

Back to support forum

Forum search