This article is mainly on the floating-point operator in JS solution to solve the problem, the need for friends can come to the reference, I hope to help you.
Once the project used to find this code on the Internet before, but under certain conditions Division and addition operations will still appear bugs individuals to this slightly optimized code as follows://Division function, to get the exact division result// Description: JavaScript division results will be error, the two floating-point numbers are more obvious when dividing. This function returns a more precise division result. Call: Accdiv (ARG1,ARG2)//return value: Arg1 divided by arg2 exact result function Accdiv (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 Accmul ((R1/R2), pow (T2-T1)); }} code is as follows://multiplication function, to get the exact result of multiplication//description: JavaScript multiplication results will be error, two floating-point numbers will be more obvious when multiplying. This function returns a more accurate result of the multiplication. Call: Accmul (ARG1,ARG2)//return value: Arg1 times Arg2 's exact result function Accmul (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 (M } Code is as follows://addition Operation Intermediate solution function Accadd (arg1, arg2) { var r1, R2, M, C;   ; try {r1 = arg1.tostring (). Split (".") [1].length} catch (e) {r1 = 0} try {r2 = arg2.tostring (). Split (".") [1].length} catch (e) {r2 = 0} c = Math.Abs (R1-R2); m = Math.pow (Math.max (R1, r2)) if (C > 0) { &nbs P var cm = Math.pow (c); if (R1 > R2) { ARG1 = N Umber (Arg1.tostring (). Replace (".", "")); ARG2 = number (arg2.tostring (). Replace (".", "")) * cm; } &nbsP Else { ARG1 = number (arg1.tostring (). Replace (" . "," ")) * cm; ARG2 = number (arg2.tostring (). Replace (".", "")); { } else { &NB Sp ARG1 = number (arg1.tostring (). Replace (".", "")); ARG2 = number (arg2.tostring (). Replace (".", "")); } return Accdiv (Arg1 + arg2), m); }