FAQ Topic - Why does parseInt('09') give an error?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Dr John Stockton

    #16
    Re: FAQ Topic - Why does parseInt('09') give an error?

    JRS: In article <4vidnYgEf_cWZW bZnZ2dnUVZ_q-dnZ2d@comcast.c om>, dated
    Mon, 4 Sep 2006 05:58:44 remote, seen in news:comp.lang. javascript,
    Randy Webb <HikksNotAtHome @aol.composted :
    >Dr John Stockton said the following on 9/2/2006 5:15 PM:
    >JRS: In article <K9udnWZ_xYY8aW XZnZ2dnUVZ_oedn Z2d@comcast.com >, dated
    >Fri, 1 Sep 2006 23:04:09 remote, seen in news:comp.lang. javascript,
    >Randy Webb <HikksNotAtHome @aol.composted :
    >>>There are circumstances in which it is right for the user to
    >>>choose the base from 8, 10, 16.
    >>There is a need to *always* choose the base for 8 and 10.
    But you would enforce a base, rather than allowing a choice.
    >Having been given an instruction that Hex can be written as 0xfff and
    >octal as 0777 otherwise decimal, anyone entering "09" deserves whatever
    >they get.
    >
    >Your imagination amuses me sometimes. If that were true, then there
    >would be *NO* need for any kind of data validation at all.
    The existence of at least one case where data validation is not needed
    does not disprove the existence of cases where data validation is
    appropriate. You've been following Logic 101 again, and that is known
    to be buggy.

    >With you, you can never tell what needs to be repeated and what doesn't.
    >
    >Perhaps you have never heard of something called "feature detection"?
    >
    >Are you kidding me? Write a lot of code to detect how parseInt works
    >when you can add 2, maybe 3, characters and have no problems at all?
    >That isn't "feature detection", that is ignorance based on writing code
    >(in your words here) "by the yard".
    With two, three, or even as many as four characters, how would you, as a
    mere coder, allow the user to choose whether he wants to enter data in
    decimal or hexadecimal?

    >>That limits your statement to Base 16.
    >>Which means that the *only* time you can *reliably* omit the Radix is
    >>Base 16. And assuming that you are only dealing with Base 2-36 that is
    >>1/35 times that it is reliable.
    >>
    >It is rare that all bases are equally likely, in my experience.
    >
    >You are the one that brought up 2-36, not me. But that is your typical
    >style is to avoid your mistakes.
    To include the possibility of bases 2 to 36 is by no means to say that
    all are equally likely. When did you last use decimal? When did you
    last use base 29?

    >Provide the Radix and it is *NEVER* an issue.
    You, the coder, cannot know the preference of the user in all cases.
    >OK, just for you, let me give you an example that just might satisfy
    >your pedantics.
    >
    >Assume that your data is coming from a user entered field:
    >
    >var inputValue = document.someFo rm.someInput.va lue;
    >
    >Where the user enters the data.
    >
    >parseInt(input Value,16);
    >
    >Now, will *THAT* satisfy your pedantic stupid arguments?
    That forces base 16, as you should know. It does not allow the user to
    choose between decimal and hexadecimal. But parseInt(inputV alue) does
    that.

    >But if the average user of the page wishes to choose between Decimal and
    >Hexadecimal. he will not be able to do so by choosing the second
    >parameter in that simple fashion. He would need, say, radio-buttons or
    >another field to choose the base.
    >
    >Aside from your grammatical errors, you don't say?
    Now we see that you do not understand the difference between a
    grammatical error and a minor typo.

    >I trust that you will study the sig of this message.
    >
    >If there were anything in your signature worth studying then I might.
    Without studying it, how could you possibly know? - except for the line
    corresponding to one in your own signature.

    It's a good idea to read the newsgroup and its FAQ.
    --
    © John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 IE 4 ©
    <URL:http://www.jibbering.c om/faq/>? JL/RC: FAQ of news:comp.lang. javascript
    <URL:http://www.merlyn.demo n.co.uk/js-index.htmjscr maths, dates, sources.
    <URL:http://www.merlyn.demo n.co.uk/TP/BP/Delphi/jscr/&c, FAQ items, links.

    Comment

    • Randy Webb

      #17
      Re: FAQ Topic - Why does parseInt('09') give an error?

      Dr John Stockton said the following on 9/4/2006 3:35 PM:
      JRS: In article <4vidnYgEf_cWZW bZnZ2dnUVZ_q-dnZ2d@comcast.c om>, dated
      Mon, 4 Sep 2006 05:58:44 remote, seen in news:comp.lang. javascript,
      Randy Webb <HikksNotAtHome @aol.composted :
      I snipped everything in your post that was irrelevant to the FAQ Entry
      that this thread was started on. If you want to give people the advice
      to try to feature detect how to deal with Base 8, then please do. I will
      reply back with how ignorant that idea is. Same for Base 10 and Base 16.
      There is a very simple solution to it:

      Always use the Radix and it will never matter.

      I now return you all to your regularly scheduled CLJ noise of VK's posts.


      --
      Randy
      Chance Favors The Prepared Mind
      comp.lang.javas cript FAQ - http://jibbering.com/faq & newsgroup weekly
      Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/

      Comment

      • Dr John Stockton

        #18
        Re: FAQ Topic - Why does parseInt('09') give an error?

        JRS: In article <pqydnWlMK-rHg5vYnZ2dnUVZ_ vKdnZ2d@comcast .com>, dated
        Mon, 11 Sep 2006 22:41:48 remote, seen in news:comp.lang. javascript,
        Randy Webb <HikksNotAtHome @aol.composted :
        >Dr John Stockton said the following on 9/4/2006 3:35 PM:
        >JRS: In article <4vidnYgEf_cWZW bZnZ2dnUVZ_q-dnZ2d@comcast.c om>, dated
        >Mon, 4 Sep 2006 05:58:44 remote, seen in news:comp.lang. javascript,
        >Randy Webb <HikksNotAtHome @aol.composted :
        >
        >I snipped everything in your post that was irrelevant to the FAQ Entry
        >that this thread was started on. If you want to give people the advice
        >to try to feature detect how to deal with Base 8, then please do. I will
        >reply back with how ignorant that idea is. Same for Base 10 and Base 16.
        >There is a very simple solution to it:
        >
        >Always use the Radix and it will never matter.
        That's a control-freak policy, and if used by the coder it deprives the
        user of the choice of radix between 8, 10, 16 (8 only in some browsers;
        but that's a user choice).

        Probably your experience is largely limited to the commercial world,
        where the only numbers deal with amounts of money and quantities of
        goods, both customarily represented in decimal. In the wider world
        there are applications in which it would be appropriate to allow the
        user to choose between decimal and hexadecimal directly, without
        auxiliary controls.

        A FAQ entry should not be unnecessarily restrictive.

        It's a good idea to read the newsgroup and its FAQ.
        --
        © John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 IE 4 ©
        <URL:http://www.jibbering.c om/faq/>? JL/RC: FAQ of news:comp.lang. javascript
        <URL:http://www.merlyn.demo n.co.uk/js-index.htmjscr maths, dates, sources.
        <URL:http://www.merlyn.demo n.co.uk/TP/BP/Delphi/jscr/&c, FAQ items, links.

        Comment

        • Randy Webb

          #19
          Re: FAQ Topic - Why does parseInt('09') give an error?

          Dr John Stockton said the following on 9/12/2006 5:42 PM:
          JRS: In article <pqydnWlMK-rHg5vYnZ2dnUVZ_ vKdnZ2d@comcast .com>, dated
          Mon, 11 Sep 2006 22:41:48 remote, seen in news:comp.lang. javascript,
          Randy Webb <HikksNotAtHome @aol.composted :
          >Dr John Stockton said the following on 9/4/2006 3:35 PM:
          >>JRS: In article <4vidnYgEf_cWZW bZnZ2dnUVZ_q-dnZ2d@comcast.c om>, dated
          >>Mon, 4 Sep 2006 05:58:44 remote, seen in news:comp.lang. javascript,
          >>Randy Webb <HikksNotAtHome @aol.composted :
          >I snipped everything in your post that was irrelevant to the FAQ Entry
          >that this thread was started on. If you want to give people the advice
          >to try to feature detect how to deal with Base 8, then please do. I will
          >reply back with how ignorant that idea is. Same for Base 10 and Base 16.
          >There is a very simple solution to it:
          >>
          >Always use the Radix and it will never matter.
          >
          That's a control-freak policy,
          No, it's a fool-proof code policy.

          and if used by the coder it deprives the user of the choice of radix
          between 8, 10, 16 (8 only in some browsers; but that's a user choice).
          No, the coder still has the ability to give the user that choice.
          Probably your experience is largely limited to the commercial world,
          where the only numbers deal with amounts of money and quantities of
          goods, both customarily represented in decimal.
          Yes, it is largely limited to the commercial world although I have
          volunteered to help with scripts in the scientific world where the Base
          is not always 10.
          In the wider world there are applications in which it would be
          appropriate to allow the user to choose between decimal and hexadecimal
          directly, without auxiliary controls.
          Example of that scenario?
          A FAQ entry should not be unnecessarily restrictive.
          It should also promote the best practice and not specifying the Radix is
          a recipe for disaster for 99% of the people who would be looking that up
          in the FAQ.

          --
          Randy
          Chance Favors The Prepared Mind
          comp.lang.javas cript FAQ - http://jibbering.com/faq & newsgroup weekly
          Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/

          Comment

          • VK

            #20
            Re: FAQ Topic - Why does parseInt('09') give an error?


            Randy Webb wrote:

            (VK highlights with **)
            <FAQENTRY>
            >
            "If no *base encoding* is given, the parseInt function decides what base the number
            is in by looking at the number. It assumes that any number beginning
            with 0x is Hexadecimal, and may assume that any number beginning with 0
            is Octal. To remove this ambiguity, always use the Radix parameter with
            parseInt".
            </FAQENTRY>
            Perfect.

            As OT in FAQ comments it is possible to discuss the IQ level of that
            C'er who decided to prefix octals with 0 (zero) and hexs with 0x
            instead of say o77 and hFF, but it will not change the standards so now
            useless
            Don't make it harder than it has to be in a FAQ Entry. In the Notes,
            maybe, but anybody with a desire to understand parseInt can master it in
            under 10 minutes.
            Full ACK

            Comment

            • Dr John Stockton

              #21
              Re: FAQ Topic - Why does parseInt('09') give an error?

              JRS: In article <yaGdnTuW1bhscp XYnZ2dnUVZ_vedn Z2d@comcast.com >, dated
              Thu, 14 Sep 2006 02:03:43 remote, seen in news:comp.lang. javascript,
              Randy Webb <HikksNotAtHome @aol.composted :
              >
              >It should also promote the best practice and not specifying the Radix is
              >a recipe for disaster for 99% of the people who would be looking that up
              >in the FAQ.
              Control freak. 99% != 100%.

              In helping the multitude, it is wrong to mislead the intelligent
              minority.

              --
              © John Stockton, Surrey, UK. ???@merlyn.demo n.co.uk Turnpike v4.00 MIME. ©
              Web <URL:http://www.merlyn.demo n.co.uk/- FAQish topics, acronyms, & links.
              Check boilerplate spelling -- error is a public sign of incompetence.
              Never fully trust an article from a poster who gives no full real name.

              Comment

              • Randy Webb

                #22
                Re: FAQ Topic - Why does parseInt('09') give an error?

                VK said the following on 9/14/2006 11:18 AM:
                Randy Webb wrote:
                >
                (VK highlights with **)
                >
                ><FAQENTRY>
                >>
                >"If no *base encoding* is given, the parseInt function decides what base the number
                >is in by looking at the number. It assumes that any number beginning
                >with 0x is Hexadecimal, and may assume that any number beginning with 0
                >is Octal. To remove this ambiguity, always use the Radix parameter with
                >parseInt".
                ></FAQENTRY>
                >
                Perfect.
                Is that sarcasm? The part that I added to it (the last line) is all that
                I changed from what is in the FAQ now.
                As OT in FAQ comments it is possible to discuss the IQ level of that
                C'er who decided to prefix octals with 0 (zero) and hexs with 0x
                instead of say o77 and hFF, but it will not change the standards so now
                useless
                Huh? We weren't discussing the IQ level of any C'er, we were discussing
                how ignorant it is to think that an FAQ Entry should be so convoluted as
                to make it nonsensical to the newbe to try to understand.

                --
                Randy
                Chance Favors The Prepared Mind
                comp.lang.javas cript FAQ - http://jibbering.com/faq & newsgroup weekly
                Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/

                Comment

                • Randy Webb

                  #23
                  Re: FAQ Topic - Why does parseInt('09') give an error?

                  Dr John Stockton said the following on 9/14/2006 4:58 PM:
                  JRS: In article <yaGdnTuW1bhscp XYnZ2dnUVZ_vedn Z2d@comcast.com >, dated
                  Thu, 14 Sep 2006 02:03:43 remote, seen in news:comp.lang. javascript,
                  Randy Webb <HikksNotAtHome @aol.composted :
                  >It should also promote the best practice and not specifying the Radix is
                  >a recipe for disaster for 99% of the people who would be looking that up
                  >in the FAQ.
                  >
                  Control freak.
                  You are bordering on becoming idiotic.
                  99% != 100%.
                  <sarcasm>
                  You don't say? I am glad you let me know, otherwise the world might have
                  thought differently.
                  <sarcasm>
                  In helping the multitude, it is wrong to mislead the intelligent
                  minority.
                  The "intelligen t minority" fall into the people who can master parseInt
                  in under 10 minutes and wouldn't be looking in the FAQ anymore. And I am
                  willing to wager that the 1% that I left out would include it anyway.

                  As I said, if you want to continue believing the garbage you are
                  spouting about how it could be advisable to leave it, then please live
                  in that fantasy world as that is all it is. I will simply repeat what I
                  said in the last post:

                  <quote>
                  If you want to give people the advice to try to feature detect how to
                  deal with Base 8, then please do. I will reply back with how ignorant
                  that idea is. Same for Base 10 and Base 16. There is a very simple
                  solution to it:

                  Always use the Radix and it will never matter.
                  </quote>

                  I did notice you didn't give me a potential scenario example to back up
                  your claim of:

                  <quote>
                  In the wider world there are applications in which it would be
                  appropriate to allow the user to choose between decimal and hexadecimal
                  directly, without auxiliary controls.
                  </quote>

                  It is trivial to give the user the option of choosing the base and to
                  write code to try to determine what the user wanted instead of using
                  "auxiliary controls" is another recipe for disaster. But, live your
                  fantasy John.

                  --
                  Randy
                  Chance Favors The Prepared Mind
                  comp.lang.javas cript FAQ - http://jibbering.com/faq & newsgroup weekly
                  Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
                  Answer:It destroys the order of the conversation
                  Question: Why?
                  Answer: Top-Posting.
                  Question: Whats the most annoying thing on Usenet?

                  Comment

                  • Dr John Stockton

                    #24
                    Re: FAQ Topic - Why does parseInt('09') give an error?

                    JRS: In article <RfidneATZp622p fYnZ2dnUVZ_umdn Z2d@comcast.com >, dated
                    Fri, 15 Sep 2006 02:24:44 remote, seen in news:comp.lang. javascript,
                    Randy Webb <HikksNotAtHome @aol.composted :
                    I will simply repeat what I
                    >said in the last post:
                    As you so often do : doubling the value adds nothing.

                    --
                    © John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 MIME. ©
                    Web <URL:http://www.merlyn.demo n.co.uk/- FAQish topics, acronyms, & links.
                    Proper <= 4-line sig. separator as above, a line exactly "-- " (SonOfRFC1036)
                    Do not Mail News to me. Before a reply, quote with ">" or "" (SonOfRFC1036)

                    Comment

                    • Dr John Stockton

                      #25
                      Re: FAQ Topic - Why does parseInt('09') give an error?

                      JRS: In article <44ee2f77$0$750 29$14726298@new s.sunsite.dk>, dated Thu,
                      24 Aug 2006 23:00:01 remote, seen in news:comp.lang. javascript, FAQ
                      server <javascript@dot internet.bepost ed :
                      >-----------------------------------------------------------------------
                      >FAQ Topic - Why does parseInt('09') give an error?
                      >-----------------------------------------------------------------------
                      >
                      >The parseInt function decides what base the number is by looking
                      >at the number. By convention it assumes that any number beginning
                      >with 0x is Hexadecimal, and otherwise any number beginning with
                      >0 is Octal. To force use of base 10 add a second parameter
                      >`` parseInt("09",1 0) ''
                      >
                      >http://msdn.microsoft.com/library/en...thparseint.asp
                      >
                      >http://docs.sun.com/source/816-6408-...ev.htm#1064173
                      >
                      >http://www.jibbering.com/faq/faq_not....html#FAQN4_12

                      While not actually matching the current FAQ topic line (change it to
                      "How and when should parseInt be used"), ISTM useful to add an
                      illustration such as
                      P = parseInt(b.offs etParent.offset Width)
                      where IIRC the format is decimal followed by 'px'.

                      --
                      © John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 MIME. ©
                      Web <URL:http://www.merlyn.demo n.co.uk/- FAQish topics, acronyms, & links.
                      Proper <= 4-line sig. separator as above, a line exactly "-- " (SonOfRFC1036)
                      Do not Mail News to me. Before a reply, quote with ">" or "" (SonOfRFC1036)

                      Comment

                      • Randy Webb

                        #26
                        Re: FAQ Topic - Why does parseInt('09') give an error?

                        Dr John Stockton said the following on 9/15/2006 5:46 PM:
                        JRS: In article <RfidneATZp622p fYnZ2dnUVZ_umdn Z2d@comcast.com >, dated
                        Fri, 15 Sep 2006 02:24:44 remote, seen in news:comp.lang. javascript,
                        Randy Webb <HikksNotAtHome @aol.composted :
                        >
                        >I will simply repeat what I
                        >said in the last post:
                        >
                        As you so often do : doubling the value adds nothing.
                        You're an idiot. If it weren't for the misleading arguments you use to
                        further advance your own agenda you wouldn't be worth replying to.

                        --
                        Randy
                        Chance Favors The Prepared Mind
                        comp.lang.javas cript FAQ - http://jibbering.com/faq & newsgroup weekly
                        Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/

                        Comment

                        Working...