javascript toFixed()方法兼容负数重写
javascript方法toFixed()可以把Number四舍五入为指定小数位数的数字,但在负数上似乎有问题,把方法提出来重写以兼容负数。 代码可放在方法调用前的任意js文件,或直接放在页面上。 Number.prototype.toFixed = function (s) { var that = this, changenum, index; if (this < 0) { that = -that; } changenum = (parseInt(that * Math.pow(10, s) + 0.5) / Math.pow(10,...