469,354 Members | 2,046 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,354 developers. It's quick & easy.

How do I convert a string integer into a number?

I want to turn the string "100,144" to numbers, to use for
resizeTo(100,144) <--- here. Please advice, or post scriptlette. Thanks

Tony Vasquez
Jul 20 '05 #1
5 23098
In article <dL***************@newsread3.news.pas.earthlink.ne t>, "Tony Vasquez"
<co**********@earthlink.net> writes:
I want to turn the string "100,144" to numbers, to use for
resizeTo(100,144) <--- here. Please advice, or post scriptlette. Thanks


var myString = "100,144";
var myNumbers = myString.split(',');
myWindow.resizeTo((+myNumbers[0]),(+myNumbers[1]));

Also:

http://jibbering.com/faq/#FAQ4_21
--
Randy
Jul 20 '05 #2
Merci, I was hoping to get a quick answer. Thanks for taking the time.

Tony Vasquez
"HikksNotAtHome" <hi************@aol.com> wrote in message
news:20***************************@mb-m03.aol.com...
In article <dL***************@newsread3.news.pas.earthlink.ne t>, "Tony Vasquez" <co**********@earthlink.net> writes:
I want to turn the string "100,144" to numbers, to use for
resizeTo(100,144) <--- here. Please advice, or post scriptlette. Thanks


var myString = "100,144";
var myNumbers = myString.split(',');
myWindow.resizeTo((+myNumbers[0]),(+myNumbers[1]));

Also:

http://jibbering.com/faq/#FAQ4_21
--
Randy

Jul 20 '05 #3
HikksNotAtHome wrote on 06 sep 2003 in comp.lang.javascript:
I want to turn the string "100,144" to numbers, to use for
resizeTo(100,144) <--- here. Please advice, or post scriptlette. Thanks


var myString = "100,144";
var myNumbers = myString.split(',');
myWindow.resizeTo((+myNumbers[0]),(+myNumbers[1]));


or you might concider eval:

var myString = "100,144";
eval("myWindow.resizeTo("+myString+")");

I know, eval is frowned upon,
but it is great executing string stored functionality.

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Jul 20 '05 #4
"Evertjan." <ex**************@interxnl.net> wrote in message
news:Xn********************@194.109.133.29...
HikksNotAtHome wrote on 06 sep 2003 in comp.lang.javascript:
I want to turn the string "100,144" to numbers, to use for
resizeTo(100,144) <-- here. Please advice, or post scriptlette.


var myString = "100,144";
var myNumbers = myString.split(',');
myWindow.resizeTo((+myNumbers[0]),(+myNumbers[1]));


or you might concider eval:

var myString = "100,144";
eval("myWindow.resizeTo("+myString+")");

I know, eval is frowned upon,
but it is great executing string stored functionality.


While eval can be used in this way, I would tend to think that if code
seemed to necessitate the use of eval then that is an indicator if bad
design in the code and that an better approach is available for just the
effort of looking.

In this case the potential use of eval is indicated by the fact that two
numbers have been stored in a comma-separated string. If the numbers had
been stored as a two dimensional array eval use would not be indicated
(and the type conversion would also have become unnecessary).

I suspect that the string data is originating in the value property of
an OPTION element, but that just may not be the best approach to the
problem. If the pairs of numbers were stored in an array of
two-dimensional arrays then the selectedIndex property of the select
could be used to index that array and extract the number values (and the
HTML OPTIONs may not need value attributes at all).

The use of eval is almost never (if not actually never) necessary in
JavaScript. On the _very_ rare occasions that eval use is indicated you
need (at minimum) the element of data unknown at run time. A list of
strings representing comma-separated pairs of numbers does not qualify
as unknown at run time.

Richard.
Jul 20 '05 #5
Thanks guys... :)

Tony Vasquez

"Richard Cornford" <Ri*****@litotes.demon.co.uk> wrote in message
news:bj*******************@news.demon.co.uk...
"Evertjan." <ex**************@interxnl.net> wrote in message
news:Xn********************@194.109.133.29...
HikksNotAtHome wrote on 06 sep 2003 in comp.lang.javascript:
I want to turn the string "100,144" to numbers, to use for
resizeTo(100,144) <-- here. Please advice, or post scriptlette.

var myString = "100,144";
var myNumbers = myString.split(',');
myWindow.resizeTo((+myNumbers[0]),(+myNumbers[1]));


or you might concider eval:

var myString = "100,144";
eval("myWindow.resizeTo("+myString+")");

I know, eval is frowned upon,
but it is great executing string stored functionality.


While eval can be used in this way, I would tend to think that if code
seemed to necessitate the use of eval then that is an indicator if bad
design in the code and that an better approach is available for just the
effort of looking.

In this case the potential use of eval is indicated by the fact that two
numbers have been stored in a comma-separated string. If the numbers had
been stored as a two dimensional array eval use would not be indicated
(and the type conversion would also have become unnecessary).

I suspect that the string data is originating in the value property of
an OPTION element, but that just may not be the best approach to the
problem. If the pairs of numbers were stored in an array of
two-dimensional arrays then the selectedIndex property of the select
could be used to index that array and extract the number values (and the
HTML OPTIONs may not need value attributes at all).

The use of eval is almost never (if not actually never) necessary in
JavaScript. On the _very_ rare occasions that eval use is indicated you
need (at minimum) the element of data unknown at run time. A list of
strings representing comma-separated pairs of numbers does not qualify
as unknown at run time.

Richard.

Jul 20 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Tome73 | last post: by
3 posts views Thread by news.hku.hk | last post: by
13 posts views Thread by Hako | last post: by
14 posts views Thread by Drew | last post: by
20 posts views Thread by Niyazi | last post: by
7 posts views Thread by elliotng.ee | last post: by
6 posts views Thread by sweeet_addiction16 | last post: by
10 posts views Thread by cmdolcet69 | last post: by
1 post views Thread by CARIGAR | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.