x


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.

more ▼

asked Nov 15 '10 at 10:11 AM

Lachee1 gravatar image

Lachee1
276 7 13 24

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

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);
more ▼

answered Nov 15 '10 at 03:53 PM

Eric5h5 gravatar image

Eric5h5
80.3k 42 132 521

thanks you for helping

Nov 18 '10 at 03:14 AM Lachee1

perfect! great answer

Jan 03 '11 at 05:55 AM Will 15
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x3465
x420
x69
x20
x2

asked: Nov 15 '10 at 10:11 AM

Seen: 6190 times

Last Updated: Aug 18 '11 at 07:02 PM