1Number.prototype.toFixedDown = function(digits) {
2 var re = new RegExp("(\\d+\\.\\d{" + digits + "})(\\d)"),
3 m = this.toString().match(re);
4 return m ? parseFloat(m[1]) : this.valueOf();
5};
6
7[ 5.467.toFixedDown(2),
8 985.943.toFixedDown(2),
9 17.56.toFixedDown(2),
10 (0).toFixedDown(1),
11 1.11.toFixedDown(1) + 22];
12
13// [5.46, 985.94, 17.56, 0, 23.1]
14