Click to See Complete Forum and Search --> : some plz help me (data convestion)


ukemike
07-25-2003, 09:24 AM
hi i got a simple question about java script. i take a string and i take character out of there ('3'). i want to do some math on this character, how do i convert it an integer.

im using the split method to get the character, but its a string so i cant do any math with it. can someone explain or point me to a direction where i can find info on data conversion functions.

thanx
mike

Gollum
07-25-2003, 09:27 AM
try

parseInt() which converts a string to an integer

Khalid Ali
07-25-2003, 09:28 AM
parseInt(str) or Number(str)

both of these will return NaN if the string being parsed is not a valid numerical value

Charles
07-25-2003, 09:36 AM
But as long as you aren't using the "additive operator", "+", JavaScript will automatically convert it. Likewise if you try to write a number it will automaticlly convert it into a string.

Khalid Ali
07-25-2003, 10:17 AM
Originally posted by Charles
But as long as you aren't using the "additive operator", "+", JavaScript will automatically convert it. .

Not good practice recommendation.

If you are using integers or numerical values in any calculations,You should always convert them into numbers...because you can not control over what users will do...