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