1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
| const $math = require('mathjs')
| export const math = {
| add () {
| return comp('add', arguments)
| },
| subtract () {
| return comp('subtract', arguments)
| },
| multiply () {
| return comp('multiply', arguments)
| },
| divide () {
| return comp('divide', arguments)
| }
| }
|
| function comp (_func, args) {
| let t = $math.chain($math.bignumber(args[0]))
| for (let i = 1; i < args.length; i++) {
| t = t[_func]($math.bignumber(args[i]))
| }
| // 防止超过6位使用科学计数法
| return parseFloat(t.done())
| }
|
|