四捨五入・切り上げ・切り捨ての関数は上記の通り、小数点の位置を基準とするので、数値を調整して行う。 小数第一位を基準とした方法 Math.round(123.456 * 10) / 10 // 出力:123.5 十の位を基準とした方法 Math.round(123.456 / 10) * 10 // 出力:120 関数にしてみる /** * 任意の桁...
関数formatDecimal() の引数に目的の数値と小数点以下桁数を与えると、その数値の小数点表現を文字列で返します。 When you give the target number and the number of decimal places to the function formatDecimal() as the argument, the function returns the formatted string of the decimal point num...