1234567891011121314151617181920212223242526272829303132333435363738 |
- import Vue from 'vue';
- import Decimal from 'decimal.js';
- const toNumber = (num) => {
- return new Decimal(num).toNumber();
- };
- const plus = (n1 = 0, n2 = 0) => {
- const number1 = new Decimal(n1);
- const number2 = new Decimal(n2);
- let result = number1.add(number2);
- result = result.toFixed(2, Decimal.ROUND_DOWN);
- return toNumber(result);
- };
- const minus = (n1 = 0, n2 = 0) => {
- const number1 = new Decimal(n1);
- const number2 = new Decimal(n2);
- let result = number1.minus(number2);
- result = result.toFixed(2, Decimal.ROUND_DOWN);
- return toNumber(result);
- };
- const multiply = (n1 = 0, n2 = 0) => {
- const number1 = new Decimal(n1);
- const number2 = new Decimal(n2);
- let result = number1.mul(number2);
- result = result.toFixed(2, Decimal.ROUND_DOWN);
- return toNumber(result);
- };
- const divide = (n1 = 0, n2 = 0) => {
- const number1 = new Decimal(n1);
- const number2 = new Decimal(n2);
- let result = number1.div(number2);
- result = result.toFixed(2, Decimal.ROUND_DOWN);
- return toNumber(result);
- };
- Vue.prototype.$plus = plus;
- Vue.prototype.$minus = minus;
- Vue.prototype.$multiply = multiply;
- Vue.prototype.$divide = divide;
|