ITeye博客

将字符串转成数字的几种方式

zhouyrt · 2010-05-10 15:33 · Core JS · Web前端 · Markdown

见以下代码:

 

typeof Number('44.5');
typeof parseInt('44.5');
typeof parseFloat('44.5');
typeof ('44.5'-0);
typeof +'44.5';
typeof ('44.5'*1);
typeof ~~'44.5';//http://james.padolsey.com/javascript/double-bitwise-not/
typeof '44.5'|0

 

还有其它的吗?

评论(1)

  1. #1 楼 · szcjlssx · 2010-08-17 12:19

    应该是

    
    console.log(typeof ('44.5'*1));  
    
    

    吧

    还有

    
    console.log(+'44.5');
    
    

评论功能维护中,当前仅展示历史评论。