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?
"9,848.48"
9848.48
parseFloat()
9
You can remove all commas from the string before calling parseFloat:
val = val.replace(',', ''); var parsed = parseFloat(val);
Remove , and convert it to float withparseFloat
,
parseFloat
parseFloat("9,848.48".replace(',', '')); // 9848.48
var number="9,848.48"; number=number.replace(/\,/g,''); number=parseInt(number); remove the comma then parse the int
var number="9,848.48"; number=number.replace(/\,/g,''); number=parseInt(number);
You just need to remove the commas from the string, try this:
parseFloat('9,848.48'.replace(',', ''));
You can use the replace method in javascript to replace "," with "".
After that, you will perform the required analysis.
Remove the comma before calling parseFloat