日期:2014-05-16 浏览次数:20417 次
Number.prototype.add = function(arg) { var n, n1, n2, s, s1, s2, ps; s1 = this.toString(); ps = s1.split('.'); n1 = ps[1] ? ps[1].length : 0; s2 = arg.toString(); ps = s2.split('.'); n2 = ps[1] ? ps[1].length : 0; n = n1 > n2 ? n1 : n2; s = Number(s1.movePoint(n)) + Number(s2.movePoint(n)); s = s.toString().movePoint(-n); return Number(s); }
Number.prototype.sub = function(arg) { var n, n1, n2, s, s1, s2, ps; s1 = this.toString(); ps = s1.split('.'); n1 = ps[1] ? ps[1].length : 0; s2 = arg.toString(); ps = s2.split('.'); n2 = ps[1] ? ps[1].length : 0; n = n1 > n2 ? n1 : n2; s = Number(s1.movePoint(n)) - Number(s2.movePoint(n)); s = s.toString().movePoint(-n); return Number(s); }
Number.prototype.mul = function(arg) { var n, n1, n2, s, s1, s2, ps; s1 = this.toString(); ps = s1.split('.'); n1 = ps[1] ? ps[1].length : 0; s2 = arg.toString(); ps = s2.split('.'); n2 = ps[1] ? ps[1].length : 0; n = n1 + n2; s = Number(s1.replace('.', '')) * Number(s2.replace('.', '')); s = s.toString().movePoint(-n); return Number(s); }
Number.prototype.div = function(arg) { var n, n1, n2, s, s1, s2, ps; s1 = this.toString(); ps = s1.split('.'); n1 = ps[1] ? ps[1].length : 0; s2 = arg.toString(); ps = s2.split('.'); n2 = ps[1] ? ps[1].length : 0; n = n1 - n2; s = Number(s1.replace('.', '')) / Number(s2.replace('.', '')); s = s.toString().movePoint(-n); return Number(s); }