Skip to content
ChartslibraryUI Get Pro

Number formatting

Every chart takes a format prop. The same format drives the axis, tooltips, labels, legends, the table view and KPI tiles, so a value is written the same way everywhere.

Presets

format 1234567 0.1234 −5000
"number" (default) 1.2M 0.12 −5,000
"integer" 1.2M 0 −5,000
"currency" $1.2M $0.12 −$5,000
"percent" – 12.3% –
"pp" (percentage points) – +0.1 pp –
"compact" 1.2M 0.12 −5.0K
"currency-compact" $1.2M $0.12 −$5.0K

Compact notation (1.2K, 4.2M, 1.3B) starts at 10,000 in labels, axes and tooltips. Below that, numbers are written in full (1,284). Tables always show full values.

Spec objects

For control, pass an object:

format={{ kind: "currency", currency: "EUR", decimals: 0, locale: "de-DE" }}
format={{ kind: "percent", decimals: 1 }}     // 0.125 → 12.5%
format={{ kind: "number", unit: "ms" }}        // 184 → 184 ms
format={{ kind: "number", decimals: 1, signed: true }} // 2.3 → +2.3
format={{ kind: "currency", unit: "m" }}       // values already in millions
Field Meaning
kind number, integer, currency, percent, pp
compact "auto" (default), true (always), false (never)
decimals Fixed decimals. Otherwise chosen per context.
currency ISO 4217 code, default USD
unit Text after the number: "ms", "trips", "x"
signed Always show + for positive values
locale BCP 47 locale, default en-US

Or pass a function: format={(v) => ${v.toFixed(1)}°C}.

Rules the formatter enforces

  • Percent values are fractions. Pass 0.125 for 12.5%. Differences between percentages are written in percentage points (+2.1 pp), not as a percent of a percent.
  • Magnitude units are never re-compacted. With unit: "m" (values already in millions), 1000 is written $1,000m, never $1.0Km. The same applies to k, bn, M, B.
  • Zero is written plainly: 0, $0, 0%, never $0.0M.
  • Tiny values don't collapse to zero: 0.00012 is written 0.00012, not 0.00.
  • Missing values are an en dash (–), never 0.
  • Negative numbers use a true minus sign (−).
  • One magnitude per axis: ticks share a suffix and the fewest decimals that keep them distinct (0, $5K, $10K, $15K).
  • Shares under 0.5% read <1% in donuts and treemaps rather than a misleading 0%.

Dates

Category axes show your labels as given. With xType="time", values can be ISO strings ("2026-03-01"), Date objects or epoch milliseconds. Date-only strings are read as UTC midnight, so a date never shifts a day in a timezone west of UTC. Tick labels are calendar-aligned (days, weeks, months, quarters, years) based on the span.

Using the formatter yourself

The helpers are exported from core/format.ts:

import { formatValue, formatDelta, formatChange, formatShare } from "@/components/charts/core/format";

formatValue(18_420_000, "currency");        // "$18.4M"
formatValue(18_420_000, "currency", { context: "table" }); // "$18,420,000"
formatDelta(0.024, "percent");              // "+2.4 pp"
formatChange(18.42, 15.96);                 // "+15.4%"
formatShare(0.004);                         // "<1%"