目录

toFixed()

此方法格式化一个具有小数点右侧特定位数的数字。

语法 (Syntax)

number.toFixed( [digits] )

参数的细节 (Parameter Details)

  • digits - 小数点后显示的位数。

返回值 (Return Value)

数字的字符串表示形式,不使用指数表示法,并且具有小数位后的确切位数。

例子 (Example)

var num3 = 177.234 
console.log("num3.toFixed() is "+num3.toFixed()) 
console.log("num3.toFixed(2) is "+num3.toFixed(2)) 
console.log("num3.toFixed(6) is "+num3.toFixed(6)) 

输出 (Output)

num3.toFixed() is 177 
num3.toFixed(2) is 177.23 
num3.toFixed(6) is 177.234000
↑回到顶部↑
WIKI教程 @2018