ES6 - toFixed() 方法



此方法將數字格式化為小數點後指定位數的數字。

語法

number.toFixed( [digits] )

引數詳情

  • digits − 小數點後顯示的位數。

返回值

不使用指數表示法且小數點後具有精確位數的數字的字串表示形式。

示例

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))

輸出

num3.toFixed() is 177
num3.toFixed(2) is 177.23
num3.toFixed(6) is 177.234000
廣告
© . All rights reserved.