Connecting Tech Pros Worldwide Forums | Help | Site Map

How to have alert("1"+1) return 2 instead of 11 ??

Ton den Hartog
Guest
 
Posts: n/a
#1: Jul 20 '05
How can I convert a string object with a vallid number in it to an integer
value ?

Ton den Hartog




Lasse Reichstein Nielsen
Guest
 
Posts: n/a
#2: Jul 20 '05

re: How to have alert("1"+1) return 2 instead of 11 ??


"Ton den Hartog" <tonh@xs4all.nl> writes:
[color=blue]
> How can I convert a string object with a vallid number in it to an integer
> value ?[/color]

There are many ways:

The shortest, prefix plus: +string
Convert to Number explicitly: Number(string)
Parse as integer or float: parseInt(string,10) or parseFloat(string)

/L
--
Lasse Reichstein Nielsen - lrn@hotpop.com
Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit.html>
'Faith without judgement merely degrades the spirit divine.'
owen
Guest
 
Posts: n/a
#3: Jul 20 '05

re: How to have alert("1"+1) return 2 instead of 11 ??



"Ton den Hartog" <tonh@xs4all.nl> wrote in message
news:bgtra6$48s$1@www-2.dev.ict.nl...[color=blue]
> How can I convert a string object with a vallid number in it to an integer
> value ?
>[/color]


answer = parseInt("1") + 1; // this returns 2




Evertjan.
Guest
 
Posts: n/a
#4: Jul 20 '05

re: How to have alert("1"+1) return 2 instead of 11 ??


Ton den Hartog wrote on 07 aug 2003 in comp.lang.javascript:[color=blue]
> How can I convert a string object with a vallid number in it to an
> integer value ?[/color]

s = "123"
resultaat = 1 * s


--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Ton den Hartog
Guest
 
Posts: n/a
#5: Jul 20 '05

re: How to have alert("1"+1) return 2 instead of 11 ??


Thanks !

NB where do I find the newsgroup FAQ ? Will be more than happy to read it !

Ton

--
Computer museum tonh: http://www.tonh.net
GGGallery: http://www.tonh.net/gggallery
- GGGallery on Tucows with a 4 cows rating !


"owen" <spam@spam.com> wrote in message
news:SwuYa.5219$R6.474623@newsfep2-win.server.ntli.net...[color=blue]
>
> "Ton den Hartog" <tonh@xs4all.nl> wrote in message
> news:bgtra6$48s$1@www-2.dev.ict.nl...[color=green]
> > How can I convert a string object with a vallid number in it to an[/color][/color]
integer[color=blue][color=green]
> > value ?
> >[/color]
>
>
> answer = parseInt("1") + 1; // this returns 2
>
>
>
>[/color]


HikksNotAtHome
Guest
 
Posts: n/a
#6: Jul 20 '05

re: How to have alert("1"+1) return 2 instead of 11 ??


In article <3f32f825$0$49106$e4fe514c@news.xs4all.nl>, "Ton den Hartog"
<tonh@xs4all.nl> writes:
[color=blue]
>Thanks !
>
>NB where do I find the newsgroup FAQ ? Will be more than happy to read it !
>
>Ton[/color]

http://www.jibbering.com/faq/
And specifically, with regards to your question:
http://www.jibbering.com/faq/#FAQ4_21
--
Randy
All code posted is dependent upon the viewing browser
supporting the methods called, and Javascript being enabled.
Closed Thread


Similar JavaScript / Ajax / DHTML bytes