Discuss / JavaScript / 关于最后的规则中第二条

关于最后的规则中第二条

Topic source

parseInt()parseFloat()转换任意类型到number

为什么不是用Number()呢,请问会有什么区别么?

廖雪峰

#2 Created at ... [Delete] [Delete and Lock User]
parseInt('12.34'); // => 12
parseFloat('12.34'); // => 12.34
Number('12.34'); // => 12.34

parseFloat(''); // NaN
Number(''); // => 0

根据需要自己选择

parseInt('10',10); //10
parseInt('10',16); //16

parse 更灵活点儿吧

根据需要


  • 1

Reply