formatAbbreviate
Formats a number to an appropriate number of decimal places and rounding, adding suffixes if applicable (ie. 1200000 to "1.2M").
Basic example
Section titled “Basic example”Rounds each number to about three significant digits and appends an SI-style suffix, so 1234 reads as 1.23k, 1234567 as 1.23M, and 1234567890 as 1.23B, while a small fraction like 0.0042 is left unabbreviated.
import {formatAbbreviate} from "@d3plus/format";
formatAbbreviate(42);
formatAbbreviate(1234);
formatAbbreviate(1234567);
formatAbbreviate(1234567890);
formatAbbreviate(0.0042);
Parameters
import {formatAbbreviate} from "@d3plus/format";
nrequiredstring|numberThe number to be formatted.
localestring|FormatLocaleDefinitionDefaulten-USThe locale config to be used. If an object is provided, the function will format the numbers according to the object. The object must include
suffixes,delimiterandcurrencyproperties.precisionstringNumber of significant digits to display.