日期:2014-05-16  浏览次数:20294 次

js浮点丢失问题
  1. //加法???
  2. Number.prototype.add?=?function(arg){ ??
  3. ????var?r1,r2,m; ??
  4. ????try{r1=this.toString().split(".")[1].length}catch(e){r1=0} ??
  5. ????try{r2=arg.toString().split(".")[1].length}catch(e){r2=0} ??
  6. ????m=Math.pow(10,Math.max(r1,r2)) ??
  7. ????return?(this*m+arg*m)/m ??
  8. } ??