js 高精度運算


使用 decimal.js 這個庫,避免報錯 "9999998990000000 is beyond boundary when transfer to integer, the results may not be accurate"

  • 錯誤
const NP = require("number-precision")
console.log(`結果`, String(NP.times(9999999, 9999999.99))) // "99999989900000"
  • 正確
const decimalJs = require("decimal.js")
const x = new decimalJs('9999999')
const res = x.times('9999999.99').toString()
console.log(`res`, res) // "99999989900000.01"


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM