Typescript-number-tofixed

提供:Dev Guides
移動先:案内検索

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

コンパイル時に、JavaScriptで同じコードが生成されます。

コードは次の出力を生成します-

num3.toFixed() is 177
num3.toFixed(2) is 177.23
num3.toFixed(6) is 177.234000