- Home /
Question by
Lachee1 · Nov 15, 2010 at 10:11 AM ·
javascriptstringconversionnumbers
how to convert string into numbers in JS
i would like to now if there is a way to convert string (like 132) into a number USING javascript.
Comment
Best Answer
Answer by Eric5h5 · Nov 15, 2010 at 03:53 PM
Use the .net feature Parse:
var s = "1234";
var i = int.Parse(s);
parseInt
does the same thing:
var s = "1234";
var i = parseInt(s);
If there's any chance the string contains non-numeric characters, use TryParse:
var s = "1234";
var i : int;
if (int.TryParse(s, i)) print ("Succeeded, and the result is " + i);