MCPcopy Create free account
hub / github.com/breck7/scroll / formatTrim

Function formatTrim

external/.d3.js:9583–9592  ·  view source on GitHub ↗
(s)

Source from the content-addressed store, hash-verified

9581
9582// Trims insignificant zeros, e.g., replaces 1.2000k with 1.2k.
9583function formatTrim(s) {
9584 out: for (var n = s.length, i = 1, i0 = -1, i1; i < n; ++i) {
9585 switch (s[i]) {
9586 case ".": i0 = i1 = i; break;
9587 case "0": if (i0 === 0) i0 = i; i1 = i; break;
9588 default: if (!+s[i]) break out; if (i0 > 0) i0 = 0; break;
9589 }
9590 }
9591 return i0 > 0 ? s.slice(0, i0) + s.slice(i1 + 1) : s;
9592}
9593
9594var prefixExponent;
9595

Callers 1

formatFunction · 0.85

Calls 1

sliceMethod · 0.80

Tested by

no test coverage detected