JavaScript字符串转数字

parseFloat('21.24abc') -> 21.24

parseInt("234blue"); -> 234
parseInt("0xA"); -> 10
parseInt("28.5"); -> 22
parseInt("yes"); -> NaN

if (isNaN(value))
{
	console.log('NaN value');
}


parseInt("AF", 16); -> 175
parseInt("10", 2); -> 2
parseInt("10", 8); -> 8
parseInt("10", 10); -> 10

如果十进制数包含前导0,那么最好采用基数10,这样才不会意外地得到八进制的值。例如:
parseInt("010"); -> 8
parseInt("010", 8); -> 8
parseInt("010", 10); -> 10

Number(false);	-> 0
Number(true); 	-> 1
Number(undefined); -> NaN
Number(null);			 -> 0
Number( "5.5 ");	 -> 5.5
Number( "56 ");		 -> 56
Number( "5.6.7 "); -> NaN
Number(new Object()) -> NaN

你可能感兴趣的:(AngularJS)