JS精度问题    Vue中使用 解决方案 math.js 

 npm install mathjs

 

 

import { create, all } from 'mathjs'
 
const config = { 
  number: 'BigNumber',
  precision: 20
}
const math = create(all, config);
export default {
  methods: {
    
     // 除
    numberExcept: function (arg1, arg2) {
      return math.divide(arg1, arg2);
    },
    //乘
    numberRide: function (arg1, arg2) {      
      return math.multiply(arg1, arg2);
    },
    //加
    numberAdd:function (arg1,arg2) {
    return math.add(arg1, arg2);
    }
    //减
    numberSub:function (arg1,arg2) {
    return math.add(arg1, -arg2);
    }
  }
 
}
 
js/引入,初始化后 ,,金额精度处理 
function getMath(number) {
    const math = window.math.create(window.math.all, {
        number: 'BigNumber',
        precision: 14
    });
    return Number(math.format(number, 14))
}

 

相关文章:

  • 2023-03-20
  • 2022-12-23
  • 2021-06-02
  • 2022-12-23
  • 2021-10-30
  • 2021-07-21
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-05-15
  • 2022-03-09
  • 2021-08-06
  • 2022-12-23
相关资源
相似解决方案