1. Floating-point number addition operation
function Numadd (arg1, arg2) {
var r1, R2, M;
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 (Ten, Math.max (R1, r2));
Return (ARG1 * m + arg2 * m)/m;
}
2. Floating-point number subtraction operation
function Floatsub (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 (Ten, Math.max (R1, r2));
Dynamic control accuracy length
n = (r1 = r2)? R1:R2;
Return (ARG1 * M-ARG2 * m)/m;
}
3. Floating-point multiplication operations
function Floatmul (arg1, arg2) {
var m = 0, S1 = arg1.tostring (), S2 = arg2.tostring ();
try {
M + = S1.split (".") [1].length
} catch (e) {
}
try {
M + = S2.split (".") [1].length
} catch (e) {
}
Return number (S1.replace (".", "")) * Number (S2.replace (".", ""))/Math.pow (ten, M);
}
4. Floating-point number division operation
function Floatdiv (arg1, arg2) {
var t1 = 0, t2 = 0, R1, R2;
try {
T1 = arg1.tostring (). Split (".") [1].length
} catch (e) {
}
try {
T2 = arg2.tostring (). Split (".") [1].length
} catch (e) {
}
With (Math) {
R1 = number (arg1.tostring (). Replace (".", ""));
r2 = number (arg2.tostring (). Replace (".", ""));
Return (R1/R2) * POW (T2-T1);
}
}
JS floating-point number add, subtract, multiply, divide.