trying to change string -> int

javascript

Solution

Did you try `intVal = parseInt(gSpread1.Text, 10);`

The 10 is called the radix, and indicate the numeral system to use.

UPDATE: There is as well a useful shortcut using the `+` symbol. eg: `+gSpread1.Text` will convert the string to a number. And will return an `integer` or a `float` depending on the string value.

Problem

I'm trying to use javascript to change a `string` to an `int`. ``` var intVal = gSpread1.Text * 1; ``` I want `intVal`'s Type to be `int`. I can get an int value, if `gSpread1.Text` is smaller than 1000. But if `gSpread1.Text` is larger than 1000, `intVal` returns `NaN` What is the correct way to use `ParseInt` to ensure that it always returns an `int` value?

Original source