3.2.0

Cell Algorithm Returning Nan??

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

The below grid is set out as follows: -

[I]
Col1 = Value to be deducted from Col2
Col2 = The Value to deduct
Col3 = The Starting Value
[/I]

[B]Enter 100.00 into row1 col1[/B]
[B]Enter 114.17 into row2 col1[/B]

Col2 returns Nan when it should return Zero??

Please advice


[Code]
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([html, num, num, num, num]);
obj.setColumnCount(3);
obj.setRowCount(2);
obj.setCellEditable(true);
document.write(obj);


obj.onCellValueChanged = function(value, col, row){
function rowByrow(col, row) {
if (row == 0) { var evaluate = obj.getCellValue(2, 0) - obj.getCellValue(0, 0);
//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(2, 0) - obj.getCellValue(0, 0);
}
}
else
{
var evaluate = obj.getCellValue(2, row - 1) - obj.getCellValue(0, row);
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(2, row) - obj.getCellValue(0, row) + obj.getCellValue(col, row - 1)
}
}
}
if (col==0) {obj.setCellData(rowByrow,1,row);}
}
[/code]

Jez (True Track Software)
October 26,
Jez,
evaluate is a javascript reserved word (command),
Try defining a different name for that variable.
C++
October 26,
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 ????????????

[Code]
obj.onCellValueChanged = function(value, col, row){
function rowByrow(col, row) {
if (row == 0)
return obj.getCellValue(2, 0) - obj.getCellValue(0, 0)
else
return obj.getCellValue(2, row) - obj.getCellValue(0, row) + obj.getCellValue(col, row - 1)
}
alert(obj.getCellValue(2, row) - obj.getCellValue(0, row) + obj.getCellValue(col, row - 1));
if (col==0) {obj.setCellData(rowByrow,1,row);}
}
[/code]
Jez (True Track Software)
October 26,
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
October 27,
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(5, row) - multi.getCellValue(2, row) + multi.getCellValue(col, row - 1) 
return count.toFixed(2);


Incidentally that should be Hazzer (True Track Software) :)
Jez (True Track Software)
October 27,

This topic is archived.

See also:


Back to support forum