收藏备用:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>解决JS运算和精度问题-decimal.js</title>
<script src="../js/decimal.min.js" type="text/javascript" charset="utf-8"></script>
</head>
<body>
<script type="text/javascript">
/*示例*/
var dc=function (r) {
return new Decimal(r);
}
//加法 add
var a = dc(0.1).add(dc(0.2));
//减法 sub
var b = dc(0.3).sub(dc(0.1));
//乘法 mul
var c = dc(37.5).mul(dc(5.5));
//除法 div
var d = dc(10).div(dc(3));
console.log(a);
console.log(b);
console.log(c);
console.log(d);
</script>
</body>
</html>