var preMath = function () {
return {
//修复四则运算浮点数精度问题
fixArithmetic: function (m, n, op) {
var a = (m + "");
var b = (n + "");
var x = 1;
var y = 1;
var c = 1;
if (a.indexOf(".") > 0) {
x = Math.pow(10, a.length - a.indexOf(".") - 1);
}
if (b.indexOf(".") > 0) {
y = Math.pow(10, b.length - b.indexOf(".") - 1);
}
switch (op) {
case '+':
c = Math.max(x, y);
m = Math.round(m * c);
n = Math.round(n * c);
return eval("(" + m + op + n + ")/" + c);
case '-':
c = Math.max(x, y);
m = Math.round(m * c);
n = Math.round(n * c);
n = -n;
op = "+";
return eval("(" + m + op + n + ")/" + c);
case '*':
c = x * y;
m = Math.round(m * x);
n = Math.round(n * y);
return eval("(" + m + op + n + ")/" + c);
case '/':
c = Math.max(x, y);
m = Math.round(m * c);
n = Math.round(n * c);
c = 1;
return eval("(" + m + op + n + ")/" + c);
}
}
};
}();