0.1 + 0.2 = 0.30000000000000004
问题,参考连接:https://github.com/camsong/bl... 浮点数的存储规则:git
展现精度问题的数据时:github
function strip(num, precision = 12) { return +parseFloat(num.toPrecision(precision)); }
toPrecision
是处理精度,精度是从左至右第一个不为0的数开始数起。toFixed
是小数点后指定位数取整,从小数点开始数起。解决精度问题:
http://mathjs.org/
https://github.com/nefe/numbe...
解决大数问题:
https://github.com/MikeMcl/bi...spa