/** * @returns {regexkit} */ /** * @returns {regexkit} */ function commonkit(){ /** * js 两个数字相乘 */ this.multiply=function(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(10,m) }; /** * js 两个数字相加 */ this.plus=function(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(10,math.max(r1,r2)) return (arg1*m+arg2*m)/m }; /** * js 两个数字相加的精确计算,避免浮点数问题,相乘使用this.multiply方法 */ this.plusprecise=function(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(10,math.max(r1,r2)) return this.plus(this.multiply(arg1,m),this.multiply(arg2,m))/m }; /** * 数组去重,如[1,2,1,2] 调用此方法后获得的结果是[1,2] * 参数 array 数组对象 * */ this.uniquearray=function(array){ try { if(array!=null&&array.length>0){ var newarray=new array(); for(var i=0;i=0){ return item; } }); } catch (e) { console.debug(e,'数组求交集出错'); return new array(); } } } /** * 调用方法 * var comomn = new commonkit(); *comomn.plus(1.1,1.3); */