Velocity Reviews > FAQ Topic - Why does 1+1 equal 11? or How do I convert a string to a number?

# FAQ Topic - Why does 1+1 equal 11? or How do I convert a string to a number?

FAQ server
Guest
Posts: n/a

 10-31-2006
-----------------------------------------------------------------------
FAQ Topic - Why does 1+1 equal 11? or How do I convert a string to a number?
-----------------------------------------------------------------------

Javascript variables are loosely typed: the conversion between a
string and a number happens automatically. Since plus (+) is also
used as in string concatenation, « '1' + 1 » is equal to « '11' »: the
String deciding what + does. To overcome this, first convert the
string to a number. For example:
« Number(varname) » or « varname*1 » or « varname-0 » or
« parseInt(varname, 10) » or « parseFloat(varname) » or « +varname ».
Prompt and form control values are strings, as is the result from
a prompt window. Convert these to numbers before performing

http://www.jibbering.com/faq/faq_not...e_convert.html

http://msdn.microsoft.com/library/en...condeclare.asp

===
Postings such as this are automatically sent once a day. Their
goal is to answer repeated questions, and to offer the content to
the community for continuous evaluation/improvement. The complete
comp.lang.javascript FAQ is at http://www.jibbering.com/faq/.
The FAQ workers are a group of volunteers.

Evertjan.
Guest
Posts: n/a

 10-31-2006
FAQ server wrote on 31 okt 2006 in comp.lang.javascript:

> -----------------------------------------------------------------------
> FAQ Topic - Why does 1+1 equal 11? or How do I convert a string to a
> number?
> -----------------------------------------------------------------------
>

[..]
>
> http://msdn.microsoft.com/library/en...56jscondeclare.
> asp

--
Evertjan.
The Netherlands.

Dr J R Stockton
Guest
Posts: n/a

 10-31-2006
In message <Xns986D6A98A97E8eejj99@194.109.133.242>, Tue, 31 Oct 2006
09:28:43, Evertjan. <(E-Mail Removed)> writes
>FAQ server wrote on 31 okt 2006 in comp.lang.javascript:
>
>> -----------------------------------------------------------------------
>> FAQ Topic - Why does 1+1 equal 11? or How do I convert a string to a
>> number?
>> -----------------------------------------------------------------------
>>

>[..]
>>
>> http://msdn.microsoft.com/library/en...56jscondeclare.
>> asp

>

If <a href="http://malch.elsop.com/quick.cgi">LinkScan</a> is put in
the FAQ, any reader will readily be able to check all of the external
links in it thereby, for existence if not for relevance.

--
(c) John Stockton, Surrey, UK. ???@merlyn.demon.co.uk Turnpike v6.05 MIME.
Web <URL:http://www.merlyn.demon.co.uk/> - FAQish topics, acronyms, & links.

Food expiry ambiguities: <URL:http://www.merlyn.demon.co.uk/date2k-3.htm#Food>

Randy Webb
Guest
Posts: n/a

 11-01-2006
Dr J R Stockton said the following on 10/31/2006 3:40 PM:

<snip>

> If <a href="http://malch.elsop.com/quick.cgi">LinkScan</a> is put in
> the FAQ, any reader will readily be able to check all of the external
> links in it thereby, for existence if not for relevance.

When feeding the FAQ URL to that site, the only error it comes up with
(aside from newsgroups references) is to the javascript.faqts.com site.
It times out (even me trying to open it).

Possible Error: 903 Connect Timeout http://javascript.faqts.com/
http://javascript.faqts.com/

The actual URL of the page is now:

<URL:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/script56/html/12a450e5-4818-4a09-9878-cd7c6cd2a248.asp>

Although I did not get a "Page Not Found" from the original URL.

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/