正常情况下console.log(0.1+0.2) //0.30000000000000004
解决方法:
add(args) { var lens = args.length; var d = 0; var sum = 0; for (var key in args) { var str = "" + args[key]; if (str.indexOf(".") != -1) { var temp = str.split(".")[1].length; d = d < temp ? temp : d; } } var m = Math.pow(10, d); for (var key in args) { sum += args[key] * m; } return sum / m; }