Js for decimal addition precision processing example

  • 2020-03-30 01:05:51
  • OfStack

zf = accAdd(zf, parseFloat("12.11")); 
//The addition function, used to get accurate addition results
//Note: javascript addition results will have errors, in the two floating point Numbers will be more obvious when adding. This function returns a more accurate addition result.
//Call: accAdd (arg1, arg2)
//Return value: the exact result of arg1 plus arg2
function accAdd(arg1,arg2){ 
var r1,r2,m; 
return (arg1*m+arg2*m)/m; 

Related articles: