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

Discussion in 'Javascript' started by FAQ server, Oct 31, 2006.

  1. FAQ server

    FAQ server Guest

    -----------------------------------------------------------------------
    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_notes/type_convert.html

    http://msdn.microsoft.com/library/en-us/script56/html/js56jscondeclare.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.
     
    FAQ server, Oct 31, 2006
    #1
    1. Advertising

  2. FAQ server

    Evertjan. Guest

    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-us/script56/html/js56jscondeclare.
    > asp


    Page not found!

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

  3. In message <Xns986D6A98A97E8eejj99@194.109.133.242>, Tue, 31 Oct 2006
    09:28:43, Evertjan. <> 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-us/script56/html/js56jscondeclare.
    >> asp

    >
    >Page not found!



    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>
     
    Dr J R Stockton, Oct 31, 2006
    #3
  4. FAQ server

    Randy Webb Guest

    Re: FAQ Topic - Why does 1+1 equal 11? or How do I convert a stringto a number?

    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/
     
    Randy Webb, Nov 1, 2006
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Mr. SweatyFinger
    Replies:
    2
    Views:
    2,008
    Smokey Grindel
    Dec 2, 2006
  2. FAQ server
    Replies:
    6
    Views:
    169
    Dr J R Stockton
    Nov 3, 2006
  3. FAQ server
    Replies:
    52
    Views:
    524
  4. FAQ server
    Replies:
    28
    Views:
    305
    Randy Webb
    Feb 23, 2007
  5. FAQ server
    Replies:
    1
    Views:
    151
    Dr J R Stockton
    Apr 15, 2007
Loading...

Share This Page