views:

96

answers:

3
var str = '0.25';

How to convert the above to 0.25?

+10  A: 

There are several ways to achieve it:

Using the unary plus operator:

var n = +str;

The Number constructor:

var n = Number(str);

The parseFloat function:

var n = parseFloat(str);
CMS
Also, for integers (only), there's `~~str` and `str | 0`
Justin Johnson
A: 

var f = parseFloat(str);

lincolnk
A: 
var num = Number(str);
Amarghosh