string Number.prototype.toPrecision(precision:uint|mixed) throws RangeError
Return a string with a given number of decimal digits after the decimal point, either in float or exponential notation, depending on the magnitude of the number.
If precision is undefined, this function returns ToString(this.[[PrimitiveValue]]). Precision must coerce (ToInteger) to a number between 1 and 21 inclusive.
Number.prototype.toPrecision.length = 1
If toPrecision is given more arguments the behaviour is undefined (see 15).
An implementation may accept and use a precision outside the 1 ... 21 range.
Number.prototype.toPrecision = function(precision){
var x = this.[[PrimitiveValue]];
if (precision === undefined) return ToString(x);
var p = ToInteger(precision);
if (isNaN(x)) return "NaN";
var s = '';
if (x < 0) {
s = '-';
x = -x;
}
if (x == Infinity) return s+'Infinity';
if (p < 1 || p > 21) throw RangeError;
if (x == 0) {
var m = new Array(p+1).join('0');
var e = 0;
} else {
var e,n; // 10^(p-1) <= n < 10^p and n*((10^(e-p+1))-1) must be as close to zero as possible. if more than two sets compete, take the largest.
var m = n+'';
if (e < -6 || e >= p) {
var a = m[0];
var b = m.substring(1);
}
if (e == 0) {
var c = "+";
var d = "0";
} else {
if (e > 0) var c = "+";
else {
var c = "-";
var e = -e;
}
var d = e+'';
}
m = s+m+"e"+c+d;
}
if (e == p-1) return s + m;
if (e >= 0) var m = m.substring(0, e+1)+'.'+m.substring(p-(e+1));
else var m = "0."+new Array(-(e+1)).join("0")+m;
return s + m;
}