js toFixed问题

来源:互联网 发布:js创建html表格 编辑:程序博客网 时间:2024/05/16 12:13
var a=12.16;console.log(a.toFixed(0)); //12console.log(a.toFixed(1)); //12.2console.log(a.toFixed(2)); //12.16console.log(a.toFixed(3)); //12.160//console.log(12.toFixed(2)); //SyntaxError  因为.被视为常量12.的一部分,所以没有.属性访问调用toFixed方法。console.log(12..toFixed(2)); //这样是没有问题,第一个.被视为常量的一部分,第二个则是属性访问运算符。

原创粉丝点击