Jump to content

Javascript Addition


gevensen

Recommended Posts

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?

Link to comment
https://forums.phpfreaks.com/topic/244532-javascript-addition/
Share on other sites

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;

Link to comment
https://forums.phpfreaks.com/topic/244532-javascript-addition/#findComment-1256061
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.