By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,480 Members | 1,743 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,480 IT Pros & Developers. It's quick & easy.

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

P: n/a
-----------------------------------------------------------------------
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
addition.

Additional Notes:

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.

Oct 30 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a
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
Page not found!

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Oct 31 '06 #2

P: n/a
In message <Xn********************@194.109.133.242>, Tue, 31 Oct 2006
09:28:43, Evertjan. <ex**************@interxnl.netwrites
>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

Page not found!

If <a href="http://malch.elsop.com/quick.cgi">LinkScan</ais 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>
Oct 31 '06 #3

P: n/a
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</ais 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/
Oct 31 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.