please tell me where i am doing mistake in following javascript code of conversion to float
i wrote following code to do some of a specifice column of gridview.. but its not working please tell me were i am missing...
function ManipulateGrid()
{
var gvDrv = document.getElementById("<%= GridView1.ClientID %>");
var gt=0.0;
for (i=1; i<gvDrv.rows.length; i++)
{
var cell = gvDrv.ro开发者_如何学Pythonws[i].cells;
var valold = cell[7].innerHTML;
var val = 0.0;
if(isNaN(parseFloat(valold)))
{
val=0.0;
else
val =valold;
}
gt = parseFloat (gt) + val;
}
alert(gt);
}
It's in and around your bracketed if block. You need to change the if block, and not throw away the conversion results.
if(isNaN(parseFloat(valold)))
{
val= 0.0;
}
else
{
val = parseFloat(valold);
}
Or even better:
var parsed = parseFloat(valold);
if(isNaN(parsed ))
{
val= 0.0;
}
else
{
val = parsed;
}
You haven't closed the curly brace for the if condition properly. Should be something like
var valueToCheck = parseFloat(valold);
if(isNaN(valueToCheck))
{
val= 0.0;
}
else
{
val = valueToCheck;
}
精彩评论