Number to string??

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Mike

    Number to string??

    Why is this converted to a string???
    var newidNumber =((idNumber/2).toFixed())+1 ;

    Thanks
    Mike
  • Henry

    #2
    Re: Number to string??

    On Nov 28, 4:35 pm, Mike <ampel...@gmail .comwrote:
    Why is this converted to a string???
    var newidNumber =((idNumber/2).toFixed())+1 ;
    Because the - toFixed - method returns a string.

    Comment

    • kendalk08

      #3
      Re: Number to string??

      On Nov 28, 10:37 am, Henry <rcornf...@rain drop.co.ukwrote :
      On Nov 28, 4:35 pm, Mike <ampel...@gmail .comwrote:
      >
      Why is this converted to a string???
      var newidNumber =((idNumber/2).toFixed())+1 ;
      >
      Because the - toFixed - method returns a string.
      when you want to use the variable as a number use eval() to return a
      number

      Comment

      • Henry

        #4
        Re: Number to string??

        On Nov 28, 4:45 pm, kendalk08 <kendal...@gmai l.comwrote:
        On Nov 28, 10:37 am, Henry <rcornf...@rain drop.co.ukwrote :
        >
        On Nov 28, 4:35 pm, Mike <ampel...@gmail .comwrote:
        >
        Why is this converted to a string???
        var newidNumber =((idNumber/2).toFixed())+1 ;
        >
        Because the - toFixed - method returns a string.
        >
        when you want to use the variable as a number use eval() to
        return a number
        No thanks, I will use the unary plus operator, the Number constructor
        called as a function, parseInt or parseFloat, depending on the
        situation. The - eval - function would be the absolute worst method to
        use, particularly as its behaviour is unpredictable whenever its
        argument is a string that does not represent a number.

        Comment

        • kendalk08

          #5
          Re: Number to string??

          On Nov 28, 10:56 am, Henry <rcornf...@rain drop.co.ukwrote :
          On Nov 28, 4:45 pm, kendalk08 <kendal...@gmai l.comwrote:
          >
          On Nov 28, 10:37 am, Henry <rcornf...@rain drop.co.ukwrote :
          >
          On Nov 28, 4:35 pm, Mike <ampel...@gmail .comwrote:
          >
          Why is this converted to a string???
          var newidNumber =((idNumber/2).toFixed())+1 ;
          >
          Because the - toFixed - method returns a string.
          >
          when you want to use the variable as a number use eval() to
          return a number
          >
          No thanks, I will use the unary plus operator, the Number constructor
          called as a function, parseInt or parseFloat, depending on the
          situation. The - eval - function would be the absolute worst method to
          use, particularly as its behaviour is unpredictable whenever its
          argument is a string that does not represent a number.
          You probably know more about Javascript, but I have been coding for
          about 2 years and the - eval - function has always worked for me.

          Comment

          • Henry

            #6
            Re: Number to string??

            On Nov 28, 4:57 pm, kendalk08 wrote:
            On Nov 28, 10:56 am, Henry wrote:
            <snip>
            >>when you want to use the variable as a number use eval() to
            >>return a number
            <snip>
            >... . The - eval - function would be the absolute worst method to
            >use, particularly as its behaviour is unpredictable whenever its
            >argument is a string that does not represent a number.
            >
            You probably know more about Javascript,
            You suggested using - eval - so we are well past "probably".
            but I have been coding for about 2 years
            It might be an idea to stop and RTFM soonish.
            and the - eval -
            function has always worked for me.
            Even the worst ways of doing things 'work', otherwise they become the
            best ways of not doing them.

            Comment

            • nolo contendere

              #7
              Re: Number to string??

              On Nov 28, 12:06 pm, Henry <rcornf...@rain drop.co.ukwrote :
              On Nov 28, 4:57 pm, kendalk08 wrote:
              >
              On Nov 28, 10:56 am, Henry wrote:
              <snip>
              >when you want to use the variable as a number use eval() to
              >return a number
              <snip>
              ... . The - eval - function would be the absolute worst method to
              use, particularly as its behaviour is unpredictable whenever its
              argument is a string that does not represent a number.
              >
              You probably know more about Javascript,
              >
              You suggested using - eval - so we are well past "probably".
              >
              There are such things as manners--this sentence was probably
              unnecessary.

              Comment

              • Randy Webb

                #8
                Re: Number to string??

                kendalk08 said the following on 11/28/2007 11:45 AM:
                On Nov 28, 10:37 am, Henry <rcornf...@rain drop.co.ukwrote :
                >On Nov 28, 4:35 pm, Mike <ampel...@gmail .comwrote:
                >>
                >>Why is this converted to a string???
                >>var newidNumber =((idNumber/2).toFixed())+1 ;
                >Because the - toFixed - method returns a string.
                >
                when you want to use the variable as a number use eval() to return a
                number
                Who fed you that line of incompetent ignorant crap?

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

                Comment

                • VK

                  #9
                  Re: Number to string??

                  On Nov 29, 3:00 am, Randy Webb <HikksNotAtH... @aol.comwrote:
                  kendalk08 said the following on 11/28/2007 11:45 AM:
                  >
                  On Nov 28, 10:37 am, Henry <rcornf...@rain drop.co.ukwrote :
                  On Nov 28, 4:35 pm, Mike <ampel...@gmail .comwrote:
                  >
                  >Why is this converted to a string???
                  >var newidNumber =((idNumber/2).toFixed())+1 ;
                  Because the - toFixed - method returns a string.
                  >
                  when you want to use the variable as a number use eval() to return a
                  number
                  >
                  Who fed you that line of incompetent ignorant crap?
                  You mean you know a script engine where eval("2") doesn't return
                  typeof "number"? Which one is that (non-ECMAScript compliant by
                  default)?

                  If you foresee some dangerous consequences of eval("2") in comparison
                  of the +"2" trick then you should spell them for the public attention
                  IMHO. After all eval is not a sex with underagers or drugs to get
                  berserk on the combination of these four letters by itself, IMHO.

                  Comment

                  • Randy Webb

                    #10
                    Re: Number to string??

                    VK said the following on 11/29/2007 12:33 AM:
                    On Nov 29, 3:00 am, Randy Webb <HikksNotAtH... @aol.comwrote:
                    >kendalk08 said the following on 11/28/2007 11:45 AM:
                    >>
                    >>On Nov 28, 10:37 am, Henry <rcornf...@rain drop.co.ukwrote :
                    >>>On Nov 28, 4:35 pm, Mike <ampel...@gmail .comwrote:
                    >>>>Why is this converted to a string???
                    >>>>var newidNumber =((idNumber/2).toFixed())+1 ;
                    >>>Because the - toFixed - method returns a string.
                    >>when you want to use the variable as a number use eval() to return a
                    >>number
                    >Who fed you that line of incompetent ignorant crap?
                    >
                    You mean you know a script engine where eval("2") doesn't return
                    typeof "number"?
                    Who said I did? I didn't. Anybody that uses eval(string) to convert
                    string to a number is an incompetent ignorant idiot.
                    Which one is that (non-ECMAScript compliant by default)?
                    ECMAScript, concern, mouses rear end.
                    If you foresee some dangerous consequences of eval("2") in comparison
                    of the +"2" trick then you should spell them for the public attention
                    IMHO. After all eval is not a sex with underagers or drugs to get
                    berserk on the combination of these four letters by itself, IMHO.
                    Somewhere on this planet, your village misses you very much.

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

                    Comment

                    • VK

                      #11
                      Re: Number to string??

                      On Nov 29, 12:25 pm, Randy Webb <HikksNotAtH... @aol.comwrote:
                      You mean you know a script engine where eval("2") doesn't return
                      typeof "number"?
                      >
                      Who said I did? I didn't. Anybody that uses eval(string) to convert
                      string to a number is an incompetent ignorant idiot.
                      And anyone who uses instead +"2" trick instead is a highly intelligent
                      experienced master who's even sh** smells just like roses? :-)

                      Cool... Got it... Some men are so easy to please, really :-)

                      Comment

                      • Randy Webb

                        #12
                        Re: Number to string??

                        VK said the following on 11/29/2007 3:28 PM:
                        On Nov 29, 12:25 pm, Randy Webb <HikksNotAtH... @aol.comwrote:
                        >>You mean you know a script engine where eval("2") doesn't return
                        >>typeof "number"?
                        >Who said I did? I didn't. Anybody that uses eval(string) to convert
                        >string to a number is an incompetent ignorant idiot.
                        >
                        And anyone who uses instead +"2" trick instead is a highly intelligent
                        experienced master who's even sh** smells just like roses? :-)
                        Your village misses you terribly.
                        --
                        Randy
                        Chance Favors The Prepared Mind
                        comp.lang.javas cript FAQ - http://jibbering.com/faq/index.html
                        Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/

                        Comment

                        Working...