How can I convert this string containing a semicolon number to a floating equivalent?

I have this string containing a semicolon number like this "9,848.48"

. I want to convert it to my floating equivalent which is 9848.48

. I tried to use parseFloat()

but I got the result 9

. How can this be done in javascript?

+3


source to share


6 answers


You can remove all commas from the string before calling parseFloat:



val = val.replace(',', '');
var parsed = parseFloat(val);

      

+1


source


Remove ,

and convert it to float withparseFloat



parseFloat("9,848.48".replace(',', ''));
// 9848.48

      

+4


source


var number="9,848.48"; number=number.replace(/\,/g,''); number=parseInt(number);

remove the comma then parse the int

+1


source


You just need to remove the commas from the string, try this:

parseFloat('9,848.48'.replace(',', ''));

      

+1


source


You can use the replace method in javascript to replace "," with "".

After that, you will perform the required analysis.

+1


source


Remove the comma before calling parseFloat

-1


source







All Articles