1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
| import { secureAdd, secureSub, secureMul, secureDiv } from '@/utils/calculate'
mounted() { this.calTestHandler() },
methods: { calTestHandler() { const operations = [ { operator: '+', method: secureAdd, a: 0.1, b: 0.2 }, { operator: '-', method: secureSub, a: 0.1, b: 0.3 }, { operator: '*', method: secureMul, a: 0.1, b: 0.2 }, { operator: '/', method: secureDiv, a: 0.1, b: 0.3 } ]
operations.forEach((operation) => { const { operator, method, a, b } = operation const result = method(a, b) console.log(`原生js ${operator} 运算:${a} ${operator} ${b}的值是${eval(a + operator + b)}`) console.log(`big.js ${operator} 运算:${a} ${operator} ${b}的值是${result}`) }) } }
|