/// Data Display
NumberFormatter
A thin Intl.NumberFormat wrapper for decimals, currency, percent, and units, in mono tabular figures.
import { NumberFormatter } from "@protocore/pds";Styles
style selects the Intl formatter: "decimal" (default, with grouping), "currency" (pair with currency), "percent", or "unit" (pair with unit). Figures render mono and tabular so columns line up.
Compact notation
notation="compact" renders 1200000 as 1.2M — for dense dashboards and stat tiles where the exact figure lives in a tooltip.
When to use it
NumberFormatter is the general-purpose number renderer: counts, ratios, measurements, quantities. It forwards its props straight to Intl.NumberFormat with an explicit default locale ("en") so a server render and its hydration are byte-identical.
For money specifically, reach for MoneyAmount — it adds minor-unit awareness and sign coloring on top of the same Intl core. A non-finite input renders the literal value with a data-invalid marker rather than a fabricated number.
Usage
Do
- Pass a raw number (or numeric string) and let Intl format it.
- Set `currency` with `style="currency"`, `unit` with `style="unit"`.
- Use `notation="compact"` for stat tiles and dense dashboards.
- Keep a fixed `locale` so SSR and client agree.
Don't
- Pre-format the number into a string; that can't localize or align.
- Use it for money with minor-units — reach for MoneyAmount.
- Rely on the runtime default locale; set it explicitly.
Accessibility
- Renders a plain `<span>`; the formatted string is the accessible text.
- Mono tabular figures keep columns of numbers vertically aligned.
NumberFormatter props
| Prop | Type | Default | Description |
|---|---|---|---|
className | string | — | |
currency | string | — | ISO 4217 code — required when `style="currency"` (e.g. `"EUR"`). |
locale | string | en | BCP-47 locale for grouping / decimal separators and unit names. Fixed and explicit so SSR and hydration agree. |
maximumFractionDigits | number | — | Maximum fractional digits. |
minimumFractionDigits | number | — | Minimum fractional digits. |
notation | enum | standard | Notation: `"standard"` or `"compact"` (`1200 → 1.2K`). |
signDisplay | enum | auto | Sign policy passed through to Intl. |
style | enum | decimal | Formatting style. |
unit | string | — | Unit identifier — required when `style="unit"` (e.g. `"kilometer"`). |
value * | string | number | — | The number to format. A numeric string off the wire is coerced. |