js小数计算BigNumber
# math.js
<script src="https://cdn.bootcdn.net/ajax/libs/mathjs/9.4.4/math.min.js"></script>
// functions and constants
math.round(math.e, 3) // 2.718
math.atan2(3, -3) / math.pi // 0.75
math.log(10000, 10) // 4
math.sqrt(-4) // 2i
math.pow([[-1, 2], [3, 1]], 2) // [[7, 0], [0, 7]]
// expressions
math.evaluate('12 / (2.3 + 0.7)') // 4
math.evaluate('12.7 cm to inch') // 5 inch
math.evaluate('sin(45 deg) ^ 2') // 0.5
math.evaluate('9 / 3 + 2i') // 3 + 2i
math.evaluate('det([-1, 2; 3, 1])') // -7
// chained operations
math.chain(3)
.add(4) // 加
.multiply(2) // 乘
.done() // 14
function funAdd(a,b){
math.config({
number: 'BigNumber'
});
return math.parser().eval(a + "+" + b);
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
参考文章 :math.js:灵活强大的JavaScript数学库 - 简书 (jianshu.com) (opens new window)
# BigNumber.js
<script src="https://cdn.bootcdn.net/ajax/libs/bignumber.js/9.0.1/bignumber.min.js"></script>
1
2
2
参考: JS中调用bignumber处理高精度小数运算 - 先锋之客 - 博客园 (cnblogs.com) (opens new window)
bignumber.js API (mikemcl.github.io) (opens new window)
# decimal.js
# big.js
<script src="https://cdn.bootcdn.net/ajax/libs/big.js/6.1.1/big.min.js"></script>
Big(record.count).times(record.price).plus(result).minus(100); // 乘、加、减、除div
1
2
3
2
3