Skip to content Skip to sidebar Skip to footer

Calculation For Comma Number Gives Nan Value

I tried to multiply 2 input where user need to key in the number but the output gives me NaN value. The input number btw have comma separator. I tried to implement the method from

Solution 1:

The problem here is that you have modified your inputs to show commas, which is totally fine, BUT you didn't remove the commas before casting/converting them to Number.

A quick test of converting a Number from string "1,234" will give you a NaN result. See screenshot:

enter image description here

Answer :

  1. Remove Comma
  2. Then cast to Number
  3. Then compute product_total_price

To remove all commas, simpy use:

yourString.replace(/,/g, '')

Hope this helps!

Post a Comment for "Calculation For Comma Number Gives Nan Value"