La razón: el cálculo se convierte en la precisión decimal binario se pierde
Por ejemplo: N-ésima potencia de 4,02 * 10 recuento de cómo es erróneo; FAQ 0,1 + 0,2 = 0,3 !. . .
Procesamiento: calculado conversión decimal
// 加法 función addNum (a, b) { var c, d, e; tratar { c = a.toString split () ( "") [1. ] .length; } Catch (f) { c = 0 ; } Prueba { d = b.toString split () [1. ( "") ] .Length; } Catch (f) { d = 0 ; } Retorno e = Math.pow (10, Math.max (c, d)), (multiNum (a, e) + multiNum (b, e)) / e; } // 减法 función subNum (a, b) { varc, d, e; tratar { c = a.toString split () ( "") [1. ] .length; } Catch (f) { c = 0 ; } Prueba { d = b.toString split () [1. ( "") ] .Length; } Catch (f) { d = 0 ; } Retorno e = Math.pow (10, Math.max (c, d)), (multiNum (a, e) - multiNum (b, e)) / e; } // 乘法 función multiNum (a, b) { var c = 0 , d = a.toString (), e = b.toString (); tratar { c + = d.split ( "") [1 ] .length; } Catch (f) {} try { c + = e.split ( "") [1 ] .length; } Catch (f) {} volver Number "( "" "). / Math.pow (10 (d.replace ( "* Número e.replace ())".")" , C); } // 除法 función divide (a, b) { var c, d, e = 0 , f = 0 ; tratar { e = a.toString split () ( "") [1. ] .length;captura(g) {} probar { f = b.toString split () [1. ( "") ] .length; } Catch (g) {} retorno c = Número (a.toString (). Sustituir ( " "" ")), d = Número (b.toString (). Sustituir (". """)), este .mul (c / d, Math.pow (10, f - e)); }