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

Function formatPrefixAuto

external/.d3.js:9596–9607  ·  view source on GitHub ↗
(x, p)

Source from the content-addressed store, hash-verified

9594var prefixExponent;
9595
9596function formatPrefixAuto(x, p) {
9597 var d = formatDecimalParts(x, p);
9598 if (!d) return x + "";
9599 var coefficient = d[0],
9600 exponent = d[1],
9601 i = exponent - (prefixExponent = Math.max(-8, Math.min(8, Math.floor(exponent / 3))) * 3) + 1,
9602 n = coefficient.length;
9603 return i === n ? coefficient
9604 : i > n ? coefficient + new Array(i - n + 1).join("0")
9605 : i > 0 ? coefficient.slice(0, i) + "." + coefficient.slice(i)
9606 : "0." + new Array(1 - i).join("0") + formatDecimalParts(x, Math.max(0, p + i - 1))[0]; // less than 1y!
9607}
9608
9609function formatRounded(x, p) {
9610 var d = formatDecimalParts(x, p);

Callers

nothing calls this directly

Calls 5

formatDecimalPartsFunction · 0.85
maxMethod · 0.80
minMethod · 0.80
sliceMethod · 0.80
joinMethod · 0.45

Tested by

no test coverage detected