Skip to content Skip to sidebar Skip to footer

How To Add Multiple Strings From Tds?

I'm trying to add multiple strings that are dollar amounts. I am getting NaN for the conversion from my parseFloat, but I remove the dollar sign and any commas. Any suggestions? I'

Solution 1:

Using the replace method like that only replaces the first instance of that pattern in a string. What's likely happening is that a number like '3,000,000' is getting changed to '3000,000', which is why you're still getting isNaN(amtF) === true.

Try this:

var amtF = amtNum.replace(/,/g, '');

The slashes instead of quotations indicate that you're searching for a regex pattern, which additionally allows you to use the g flag. This stands for global and means that all instances of that pattern will be replaced.

EDIT: The issue is likely that you forgot to initialize subtotal as zero. Change this:

var subTotal;

to this:

var subTotal = 0;

Post a Comment for "How To Add Multiple Strings From Tds?"