formatNumber
formatNumber(
value,format?,defaultLocale?):string
Defined in: packages/core/src/i18n/number-format.ts:122
Format a number with MapLibre number-format options.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
value | number | the number. |
format | NumberFormat | { locale, currency, unit, min-fraction-digits, max-fraction-digits }, or an older ",.2f" string. |
defaultLocale? | string | the locale when format names none (usually the page’s language, elementLanguage); undefined means the browser’s. |
Returns
Section titled “Returns”string
the formatted text. An option Intl rejects (an unknown currency or unit, a malformed locale) is dropped with one console warning, never thrown.
Remarks
Section titled “Remarks”Locale tags are read with normalizeLocale (en_US → en-US). A
locale or option Intl rejects never loses more than it must: the
options are tried under the default locale, then the browser’s, then
grouping and fraction digits alone — the bare String(value) is the last
resort.
Example
Section titled “Example”formatNumber(1234567.891, { locale: "de-DE", "max-fraction-digits": 1 }); // "1.234.567,9"formatNumber(12.5, { currency: "EUR" }, "fr"); // "12,50 €"formatNumber(10, {}, "en") + "–" + formatNumber(25, {}, "en"); // "10–25"