Es6-tofixed
提供:Dev Guides
ES6-toFixed()
このメソッドは、小数の右側にある特定の桁数で数値をフォーマットします。
構文
number.toFixed( [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