javascript里,使用浮点数计算,会出现明显的精度问题,比如0.1+0.2,结果是0.30000000000000004
可以使用decimal.js来处理这个问题。
github:https://github.com/MikeMcl/decimal.js
https://zhuanlan.zhihu.com/p/274327350
通过npm安装
npm install --save decimal.js
微信小程序npm相关信息:
https://developers.weixin.qq.com/miniprogram/dev/devtools/npm.html
在小程序里通过npm安装方法如下:
https://developers.weixin.qq.com/community/develop/article/doc/0008aecec4c9601e750be048d51c13
最近做的“计算器全能版”小程序已经上线: