Number.prototype.toFixed() | toFixed js
toFixed()方法會使用定點小數表示法(fixed-pointnotation)來格式化數字。參數[1]digits小數位[2]選擇性輸入。顯示數值至多少個小數點,範圍由0到20之間,執行時或可支援非常大範圍的數值。如果無輸入會默認做0。回傳值[3]一個代表以定點小數表示法(fixed-pointnotation)格式化數字後的字串。例外[4]RangeError[5]Ifdigitsistoosmallortoolarge.Valuesbetween0and100,inclusive,willnotcauseaRangeError[6].Implementationsareallowedtosupportlargerandsmallervaluesaschosen.TypeError[7]Ifthismethodisinvokedonanobjectthatisn...
toFixed() 方法會使用定點小數表示法(fixed-point notation)來格式化數字。
參數[1]digits 小數位[2]選擇性輸入。顯示數值至多少個小數點,範圍由 0 到 20 之間,執行時或可支援非常大範圍的數值。如果無輸入會默認做 0。
回傳值[3]一個代表以定點小數表示法(fixed-point notation)格式化數字後的字串。
例外[4]RangeError[5]If digits is too small or too large. Values between 0 and 100, inclusive, will not cause a RangeError[6]. Implementations are allowed to support larger and smaller values as chosen.
TypeError[7]If this method is invoked on an object that is not a Number[8].
toFixed() returns a string representation of numObj that does not use exponential notation and has exactly digits digits after the decimal place. The number is rounded if necessary, and the fractional part is padded with zeros if necessary so that it has the specified length. If numObj is greater than 1e+21, this method simply calls Number.prototype.toString()[9] and returns a string in exponential notation.
Using toFixed[10]var numObj = 12345.6789; numObj.toFixe...