扫码一下
查看教程更方便
tofixed() 方法可把 number 四舍五入为指定小数位数的数字。
number.tofixed( [digits] )
digits- 小数点后出现的位数。
字符串表示数量不使用指数记数法,小数点后有固定的 x 位数字
所有主流浏览器都支持 tofixed 方法。
javascript tofixed() method
输出结果:
num.tofixed() is : 177
num.tofixed(6) is : 177.123400
num.tofixed(1) is : 177.1
(1.23e 20).tofixed(2) is:123000000000000000000.00
(1.23e-10).tofixed(2) is : 0.00