Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > JavaScript > FAQ Topic - Why...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 1 Topic 35488 of 36382
Post > Topic >>

FAQ Topic - Why does 1+1 equal 11? or How do I convert a string to a number? (2008-05-06)

by "FAQ server" <javascript@[EMAIL PROTECTED] > May 5, 2008 at 11:00 PM

-----------------------------------------------------------------------
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: ` +varname ` or ` Number(varname) ` or
` parseInt(varname, 10) ` or ` parseFloat(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_notes/type_convert.html

http://msdn2.microsoft.com/en-us/library/67defydd.aspx


-- 
 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://jibbering.com/faq/index.html.
 The FAQ workers are a group of volunteers.  The sendings of these 
 daily posts are proficiently hosted by http://www.pair.com.
 




 1 Posts in Topic:
FAQ Topic - Why does 1+1 equal 11? or How do I convert a string
"FAQ server" &l  2008-05-05 23:00:02 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Sat Jul 26 5:17:13 CDT 2008.