1 vue项目安装Decimal
npm install decimal.js
2 注意
运算结果是Decimal对象,需要使用.toNumber()转为数字
3 加 add
const Decimal = require('decimal.js')const num1 = Decimal("5");const num2 = Decimal("3");const remainder = num1.add(num2);
4 减 sub
const Decimal = require('decimal.js')const num1 = Decimal("5");const num2 = Decimal("3");const remainder = num1.sub(num2);
5 乘 mul
const Decimal = require('decimal.js')const num1 = Decimal("5");const num2 = Decimal("3");const remainder = num1.mul(num2);
6 除 div
const Decimal = require('decimal.js')const num1 = Decimal("5");const num2 = Decimal("3");const remainder = num1.div(num2);
7 求余 modulo
const Decimal = require('decimal.js')const num1 = Decimal("5");const num2 = Decimal("3");const remainder = num1.modulo(num2);