JS精確到指定位數的小數

將數字四捨五入到指定的小數位數。 使用 Math.round() 和模板量將數字四捨五入爲指定的小數位數。 省略第二個參數 decimals ,數字將被四捨五入到一個整數。javascript const NumFun= (n, decimals = 0) => Number(`${Math.round(`${n}e${decimals}`)}e-${decimals}`) NumFun(3.14
相關文章
相關標籤/搜索