The function code is as follows:
Copy Code code as follows:
/*
* Arithmetic precision correction function
* M value 1 (number)
* N value 2 (number)
* OP operator (string)
*/
function Fixmath (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 (A.length-a.indexof (".")-1);
}
if (B.indexof (".") > 0) {
y = Math.pow (B.length-b.indexof (".")-1);
}
Switch (OP)
{
Case ' + ':
Case '-':
c = Math.max (x,y);
m = Math.Round (m*c);
n = math.round (n*c);
Break
Case ' * ':
c = X*y
m = Math.Round (m*x);
n = math.round (n*y);
Break
Case '/':
c = Math.max (x,y);
m = Math.Round (m*c);
n = math.round (n*c);
c = 1;
Break
}
Return eval ("+m+op+n+")/"+c";
}
The function usage is as follows:
Copy Code code as follows:
Fixmath (2.3, 1.9, ' * ')
Fixmath (1.98, 1.9, '-')
Fixmath (83.50, 74.15, '-')