How do I convert a string integer into a number?

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

    How do I convert a string integer into a number?

    I want to turn the string "100,144" to numbers, to use for
    resizeTo(100,14 4) <--- here. Please advice, or post scriptlette. Thanks

    Tony Vasquez


  • HikksNotAtHome

    #2
    Re: How do I convert a string integer into a number?

    In article <dL96b.591$PE6. 313@newsread3.n ews.pas.earthli nk.net>, "Tony Vasquez"
    <condorschool@e arthlink.net> writes:
    [color=blue]
    >I want to turn the string "100,144" to numbers, to use for
    >resizeTo(100,1 44) <--- here. Please advice, or post scriptlette. Thanks[/color]

    var myString = "100,144";
    var myNumbers = myString.split( ',');
    myWindow.resize To((+myNumbers[0]),(+myNumbers[1]));

    Also:


    --
    Randy

    Comment

    • Tony Vasquez

      #3
      Re: How do I convert a string integer into a number?

      Merci, I was hoping to get a quick answer. Thanks for taking the time.

      Tony Vasquez


      "HikksNotAtHome " <hikksnotathome @aol.com> wrote in message
      news:2003090521 0602.14837.0000 2759@mb-m03.aol.com...[color=blue]
      > In article <dL96b.591$PE6. 313@newsread3.n ews.pas.earthli nk.net>, "Tony[/color]
      Vasquez"[color=blue]
      > <condorschool@e arthlink.net> writes:
      >[color=green]
      > >I want to turn the string "100,144" to numbers, to use for
      > >resizeTo(100,1 44) <--- here. Please advice, or post scriptlette. Thanks[/color]
      >
      > var myString = "100,144";
      > var myNumbers = myString.split( ',');
      > myWindow.resize To((+myNumbers[0]),(+myNumbers[1]));
      >
      > Also:
      >
      > http://jibbering.com/faq/#FAQ4_21
      > --
      > Randy[/color]


      Comment

      • Evertjan.

        #4
        Re: How do I convert a string integer into a number?

        HikksNotAtHome wrote on 06 sep 2003 in comp.lang.javas cript:[color=blue][color=green]
        >>I want to turn the string "100,144" to numbers, to use for
        >>resizeTo(100, 144) <--- here. Please advice, or post scriptlette. Thanks[/color]
        >
        > var myString = "100,144";
        > var myNumbers = myString.split( ',');
        > myWindow.resize To((+myNumbers[0]),(+myNumbers[1]));[/color]

        or you might concider eval:

        var myString = "100,144";
        eval("myWindow. resizeTo("+mySt ring+")");

        I know, eval is frowned upon,
        but it is great executing string stored functionality.

        --
        Evertjan.
        The Netherlands.
        (Please change the x'es to dots in my emailaddress)

        Comment

        • Richard Cornford

          #5
          Re: How do I convert a string integer into a number?

          "Evertjan." <exjxw.hannivoo rt@interxnl.net > wrote in message
          news:Xns93EE630 FEA7EAeejj99@19 4.109.133.29...[color=blue]
          >HikksNotAtHo me wrote on 06 sep 2003 in comp.lang.javas cript:[color=green][color=darkred]
          >>>I want to turn the string "100,144" to numbers, to use for
          >>>resizeTo(100 ,144) <-- here. Please advice, or post scriptlette.[/color]
          >>
          >> var myString = "100,144";
          >> var myNumbers = myString.split( ',');
          >> myWindow.resize To((+myNumbers[0]),(+myNumbers[1]));[/color]
          >
          >or you might concider eval:
          >
          >var myString = "100,144";
          >eval("myWindow .resizeTo("+myS tring+")");
          >
          >I know, eval is frowned upon,
          >but it is great executing string stored functionality.[/color]

          While eval can be used in this way, I would tend to think that if code
          seemed to necessitate the use of eval then that is an indicator if bad
          design in the code and that an better approach is available for just the
          effort of looking.

          In this case the potential use of eval is indicated by the fact that two
          numbers have been stored in a comma-separated string. If the numbers had
          been stored as a two dimensional array eval use would not be indicated
          (and the type conversion would also have become unnecessary).

          I suspect that the string data is originating in the value property of
          an OPTION element, but that just may not be the best approach to the
          problem. If the pairs of numbers were stored in an array of
          two-dimensional arrays then the selectedIndex property of the select
          could be used to index that array and extract the number values (and the
          HTML OPTIONs may not need value attributes at all).

          The use of eval is almost never (if not actually never) necessary in
          JavaScript. On the _very_ rare occasions that eval use is indicated you
          need (at minimum) the element of data unknown at run time. A list of
          strings representing comma-separated pairs of numbers does not qualify
          as unknown at run time.

          Richard.


          Comment

          • Tony Vasquez

            #6
            Re: How do I convert a string integer into a number?

            Thanks guys... :)

            Tony Vasquez

            "Richard Cornford" <Richard@litote s.demon.co.uk> wrote in message
            news:bjci9r$6gr $1$8302bc10@new s.demon.co.uk.. .[color=blue]
            > "Evertjan." <exjxw.hannivoo rt@interxnl.net > wrote in message
            > news:Xns93EE630 FEA7EAeejj99@19 4.109.133.29...[color=green]
            > >HikksNotAtHo me wrote on 06 sep 2003 in comp.lang.javas cript:[color=darkred]
            > >>>I want to turn the string "100,144" to numbers, to use for
            > >>>resizeTo(100 ,144) <-- here. Please advice, or post scriptlette.
            > >>
            > >> var myString = "100,144";
            > >> var myNumbers = myString.split( ',');
            > >> myWindow.resize To((+myNumbers[0]),(+myNumbers[1]));[/color]
            > >
            > >or you might concider eval:
            > >
            > >var myString = "100,144";
            > >eval("myWindow .resizeTo("+myS tring+")");
            > >
            > >I know, eval is frowned upon,
            > >but it is great executing string stored functionality.[/color]
            >
            > While eval can be used in this way, I would tend to think that if code
            > seemed to necessitate the use of eval then that is an indicator if bad
            > design in the code and that an better approach is available for just the
            > effort of looking.
            >
            > In this case the potential use of eval is indicated by the fact that two
            > numbers have been stored in a comma-separated string. If the numbers had
            > been stored as a two dimensional array eval use would not be indicated
            > (and the type conversion would also have become unnecessary).
            >
            > I suspect that the string data is originating in the value property of
            > an OPTION element, but that just may not be the best approach to the
            > problem. If the pairs of numbers were stored in an array of
            > two-dimensional arrays then the selectedIndex property of the select
            > could be used to index that array and extract the number values (and the
            > HTML OPTIONs may not need value attributes at all).
            >
            > The use of eval is almost never (if not actually never) necessary in
            > JavaScript. On the _very_ rare occasions that eval use is indicated you
            > need (at minimum) the element of data unknown at run time. A list of
            > strings representing comma-separated pairs of numbers does not qualify
            > as unknown at run time.
            >
            > Richard.
            >
            >[/color]


            Comment

            Working...