Skip to content

formatDefaultLocale

An extension to d3’s formatDefaultLocale function that allows setting the locale globally for formatters.

Sets the decimal mark, thousands separator, digit grouping, and currency affixes that every subsequent format call uses, the same way d3’s formatDefaultLocale does. It is global state: the German definition flips the separators for all formatters until another definition replaces it.

import {format, formatDefaultLocale} from "@d3plus/format";

formatDefaultLocale({
  decimal: ",",
  thousands: ".",
  grouping: [3],
  currency: ["", "\u00a0€"],
});
format(",.2f")(1234567.891);
format("$,.2f")(1234567.891);

Parameters

import {formatDefaultLocale} from "@d3plus/format";
definitionrequiredFormatLocaleDefinition

The localization definition.