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]
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,