math.js的加减乘除

math.js

https://mathjs.org/

引用js

<script src="https://unpkg.com/mathjs@7.0.1/dist/math.min.js" type="text/javascript"></script>

或者

npm install mathjs

加减乘除demo

// 0.1+0.2
math.format(math.chain(math.bignumber(0.1)).add(math.bignumber(0.2)).done());
 
// 0.2-0.1
math.format(math.chain(math.bignumber(0.2)).subtract(math.bignumber(0.1)).done());
 
// 0.1*0.2
math.format(math.chain(math.bignumber(0.1)).multiply(math.bignumber(0.2)).done());
 
// 0.1/0.2
math.format(math.chain(math.bignumber(0.1)).divide(math.bignumber(0.2)).done());

参考自:https://www.cnblogs.com/wxhhts/p/11694306.html

代码只是方便up主记忆,仅供参考~~

类似文章

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注