Forum : How to convert a string to a number using JavaScript?
Brief description  about Online courses   join in Online courses
View Balu  Prasad 's Profile

How to convert a string to a number using JavaScript?

How to convert a string to a number using JavaScript?
Asked by Balu Prasad | Mar 22, 2010 |  Reply now
Replies (1)
View teacher siliconindia 's Profile
Hi Balu,
You can use the parseInt() and parseFloat() methods. Notice that extra letters following a valid number are ignored, which is kinda wierd but convenient at times.
parseInt("100") ==> 100
parseFloat("98.6") ==> 98.6
parseFloat("98.6 is a common temperature.") ==> 98.6
parseInt("aa") ==> Nan //Not a Number
parseInt("aa",16) ==> 170 //you can supply a radix or base
Mar 22, 2010