vue js计算精度问题处理,兼容XP系统
js计算精度问题(浮点数误差,大数计算出错)
JavaScript 运算时经常遇到会 0.000000001 和 0.999999999 这样奇怪的结果。
网上教程一大篇,原理请百度,抄作业往下看!!!
对此问题借用Big.js进行处理,亲测Big.js可以兼容XP系统,某些插件在xp上运行会报错,已踩坑!!!
目前已经封装好插件,直接下载使用即可
也可以自行下载Big.js
抄作业:
npm install geom-math --save
在需要使用的文件引用
import math from 'geom-math' //计算
或者在main.js里面全局引用
import math from 'geom-math'Vue.prototype.$math = math
使用方法:
//加法this.$math.add(a, b)
//例如:
let num = this.$math.add(1, 2)
console.log(num) // 3
//减法
this.$math.subtract(a, b)
//例如:
let num = this.$math.subtract(1, 2)
console.log(num) // -1
// 乘法
this.$math.multiply(a, b)
//例如:
let num = this.$math.multiply(1, 2)
console.log(num) // 2
// 除法
this.$math.divide(a, b)
//例如:
let num = this.$math.divide(1, 2)
console.log(num) // 0.5
以上是 vue js计算精度问题处理,兼容XP系统 的全部内容, 来源链接: utcz.com/z/380987.html