/**
* 加法
* @param a
* @param b
* @returns {Number}
*/
function accAdd(a, b) {
var c, d, e;
if(undefined==a||null==a||""==a||isNaN(a)) {
a=0;
}
if(undefined==b||null==b||""==b||isNaN(b)) {
b=0;
}
try {
c = a.toString().split(".")[1].length;
} catch (f) {
c = 0;
}
try {
d = b.toString().split(".")[1].length;
} catch (f) {
d = 0;
}
e = Math.pow(10, Math.max(c, d));
return (floatMul(a, e) + floatMul(b, e)) / e;
}
/**
* 減法
* @param arg1
* @param arg2
* @returns
*/
accSub(arg1, arg2) {
var r1, r2, m, n;
try {
r1 = arg1.toString().split(".")[1].length;
} catch (e) {
r1 = 0;
}
try {
r2 = arg2.toString().split(".")[1].length;
} catch (e) {
r2 = 0;
}
m = Math.pow(10, Math.max(r1, r2));
//動(dòng)態(tài)控制精度長度
n = (r1 >= r2) ? r1 : r2;
return ((arg1 * m - arg2 * m) / m).toFixed(n);
},
/***
* 乘法
* @param arg1
* @param arg2
* @returns
*/
accMul(arg1, arg2) {
var m = 0,
s1 = arg1.toString(),
s2 = arg2.toString();
try {
m += s1.split(".")[1].length
} catch (e) {console.log(e)}
try {
m += s2.split(".")[1].length
} catch (e) {console.log(e)}
return Number(s1.replace(".", "")) * Number(s2.replace(".", "")) / Math.pow(10, m);
},
function accDiv(a, b) {
var c, d, e = 0,
f = 0;
try {
e = a.toString().split(".")[1].length;
} catch (g) {}
try {
f = b.toString().split(".")[1].length;
} catch (g) {}
return c = Number(a.toString().replace(".", "")), d = Number(b.toString().replace(".", "")), accMul(c / d, Math.pow(10, f - e));
}
/**
* 四舍五入保留兩位小數(shù)
*/
accRound(num) {
return Math.round(num*100)/100
},