保留小数位数

toFixed() 返回字符串值,它包含了指定位数小数的数字:

var x = 9.656;
x.toFixed(0);           // 返回 10
x.toFixed(2);           // 返回 9.66
x.toFixed(4);           // 返回 9.6560
x.toFixed(6);           // 返回 9.656000

 

posted @ 2021-10-22 11:30  龙儿哥哥的博客  阅读(32)  评论(0编辑  收藏  举报