Parsing an input to Int in javascript.

Posted by Puneet20884 under JavaScript category on | Views : 5240
There is an inbuilt function for it
The function provided is parseInt
We can use it in two ways
1) Parsing the value to default number type
2) Parsing the value to a special number system

The usage for both respectively is:

alert(parseInt("10")) // Or value or innertext of a control
alert(parseInt('aaa')) // Or value or innertext of a control, it will return Nan, showing that the value is not a number


alert(parseInt("10",numbertype)) , e.g.  alert(parseInt("10",10)) //etc. Or value or innertext of a control
there are different number types to which the given input can be parsed as per the requirement.

Comments or Responses

Login to post response