gevensen Posted August 11, 2011 Share Posted August 11, 2011 Need to help on javascript addition I am retrieving a variable using the following i declare the variable either var TDIncome=parseFloat('0.00'); or var TDIncome=0; I then add it inside a tr loop Where I convert the text MyInc to a float var MyInc=$(this).find("#incometd").text(); TDIncome=TDIncome+parseFloat(MyInc); When I bring it up in an alert box I get NaN displayed Any ideas what I am doing wrong? Quote Link to comment https://forums.phpfreaks.com/topic/244532-javascript-addition/ Share on other sites More sharing options...
nogray Posted August 11, 2011 Share Posted August 11, 2011 Use an alert on MyInc to check the text value. if parseFloat can't find a number it will return a NaN. You can check for it by using the isNaN(value) function. e.g. var my_parse_float = parseFloat(MyInc); if (isNaN(my_parse_float)) my_parse_float = 0; Quote Link to comment https://forums.phpfreaks.com/topic/244532-javascript-addition/#findComment-1256061 Share on other sites More sharing options...
gevensen Posted August 11, 2011 Author Share Posted August 11, 2011 I just found Number(MyInc) works fine.. thanks Quote Link to comment https://forums.phpfreaks.com/topic/244532-javascript-addition/#findComment-1256106 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.