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

Function formatDecimalParts

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

Source from the content-addressed store, hash-verified

9489// significant digits p, where x is positive and p is in [1, 21] or undefined.
9490// For example, formatDecimalParts(1.23) returns ["123", 0].
9491function formatDecimalParts(x, p) {
9492 if ((i = (x = p ? x.toExponential(p - 1) : x.toExponential()).indexOf("e")) < 0) return null; // NaN, ±Infinity
9493 var i, coefficient = x.slice(0, i);
9494
9495 // The string returned by toExponential either has the form \d\.\d+e[-+]\d+
9496 // (e.g., 1.2e+3) or the form \de[-+]\d+ (e.g., 1e+3).
9497 return [
9498 coefficient.length > 1 ? coefficient[0] + coefficient.slice(2) : coefficient,
9499 +x.slice(i + 1)
9500 ];
9501}
9502
9503function exponent(x) {
9504 return x = formatDecimalParts(Math.abs(x)), x ? x[1] : NaN;

Callers 3

exponentFunction · 0.85
formatPrefixAutoFunction · 0.85
formatRoundedFunction · 0.85

Calls 2

indexOfMethod · 0.80
sliceMethod · 0.80

Tested by

no test coverage detected