I have a number that I need to pull from my html:
<span>123,456.78</span>
How can I convert this string into a number that I can do math on?
var numberString = $('span').text();
var realNumber = Number(numberString); //returns NaN
A jQuery-only solution would be okay.
I’m not sure what
realNumberdoes, but here’s how I’d convert that string into a number:This removes the commas, then uses the
+unary operator to convert the string to a number. In your example, the result is the number123456.78.