var number1 = Number("1123 mm");
I want to parse this String to a number, 1123 to be exactly. However, I get NaN if I do this. Does anyone have a suggestion how I could parse this to a number?
var number1 = Number("1123 mm");
I want to parse this String to a number, 1123 to be exactly. However, I get NaN if I do this. Does anyone have a suggestion how I could parse this to a number?
Just as in JavaScript, you can use parseInt
and parseFloat
.
var number1 = parseInt("1123 mm", 10); // 1123
var number2 = parseFloat("115.65 lkjsdf"); // 115.65
Number only works for valid number strings and booleans.
You want to use parseInt()
var number1 = parseInt("1123 mm");