converting strings

Results 1 to 2 of 2

Thread: converting strings

  1. #1
    Join Date
    Dec 1969

    Default converting strings

    If a variable i contains a string "1", and I use i++ (or i = i + 1), will it be converted to integer 1 then incremented?<BR><BR>Also if variable b contains string "0", will this be boolean true or false? I know that "string" is boolean true, as it is not 0, and anything except 0 is true, but what about "0".

  2. #2
    Join Date
    Dec 1969

    Default play it safe: parseInt

    &nbsp;<BR>var i = "1" <BR>...<BR><BR>i = ++ parseInt(i)<BR>...<BR><BR>if ( parseInt(b) ) ...<BR><BR>**************<BR><BR>If the variable is already a numeric data type, parseInt still works. So no harm using it when you aren&#039;t sure. Though I have to ask why you wouldn&#039;t be sure.<BR><BR>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts