broken toFixed implementation
<p>The default implementation of javascript's "Number.toFixed" appears to be a bit broken. </p>

<pre><code>console.log((8.555).toFixed(2));    // returns 8.56
console.log((8.565).toFixed(2));    // returns 8.57
console.log((8.575).toFixed(2));    // returns 8.57
console.log((8.585).toFixed(2));    // returns 8.59
</code></pre>

<p>I need a rounding method that is more consistent than that.</p>

<p>In the range between 8.500 and 8.660 the following numbers don't round up correctly.</p>

<pre><code>8.575
8.635
8.645
8.655
</code></pre>

<p>I've tried to fix the prototype implementation as follows, but it's only half way there. Can anyone suggest any change that would make it work more consistently?</p>

<pre><code>Number.prototype.toFixed = function(decimalPlaces) {
    var factor = Math.pow(10, decimalPlaces || 0);
    var v = (Math.round(this * factor) / factor).toString();
    if (v.indexOf('.') &gt;= 0) {
        return v + factor.toString().substr(v.length - v.indexOf('.'));
    }
    return v + '.' + factor.toString().substr(1);
};
</code></pre>
