You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
15 lines
368 B
15 lines
368 B
5 years ago
|
export default function(x, p) {
|
||
|
x = x.toPrecision(p);
|
||
|
|
||
|
out: for (var n = x.length, i = 1, i0 = -1, i1; i < n; ++i) {
|
||
|
switch (x[i]) {
|
||
|
case ".": i0 = i1 = i; break;
|
||
|
case "0": if (i0 === 0) i0 = i; i1 = i; break;
|
||
|
case "e": break out;
|
||
|
default: if (i0 > 0) i0 = 0; break;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
return i0 > 0 ? x.slice(0, i0) + x.slice(i1 + 1) : x;
|
||
|
}
|