English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

How do you convert a string variable to a interger/float variable?

2007-03-25 01:55:10 · 4 answers · asked by Anonymous in Computers & Internet Programming & Design

4 answers

it's

int num = Integer.parseInt(String);

or

float num = Float.parseFloat(String);

2007-03-25 02:48:30 · answer #1 · answered by T-man 2 · 0 2

above answers are bad syntax:

var s = "12.1 monkeys";
var i = parseInt( s ); // assigns 12
var f = parseFloat( s ); // assigns 12.1

Note that JavaScript does not really differentiate between integers and floating points. The datatype is just "Number".

2007-03-25 11:15:48 · answer #2 · answered by Fabian 2 · 0 1

Google gave the answer in the first hit (and probably a thousand more)

int a = parseInt(somestring);

2007-03-25 09:33:45 · answer #3 · answered by Anonymous · 1 1

i hope that the above two answers satisfy the question.... :-)

2007-03-25 09:55:18 · answer #4 · answered by aru.mugam 2 · 0 3

fedest.com, questions and answers