Skip to content

Format Presets

presets is a collection of named Intl.NumberFormatOptions objects for the most common number formatting patterns. Pass them directly as formatOptions.

import { presets } from "raqam";
// or
import { presets } from "raqam/core";
import { presets } from "raqam";
<NumberField.Root formatOptions={presets.currency("USD")} locale="en-US" />
<NumberField.Root formatOptions={presets.percent} locale="en-US" />
<NumberField.Root formatOptions={presets.compact} locale="en-US" />
presets.currency("USD")
// → { style: "currency", currency: "USD" }

Standard currency formatting. Shows symbol + thousands separators.

LocaleValueFormatted
en-US1234.56$1,234.56
de-DE1234.561.234,56 €
ja-JP1234¥1,234
fa-IR1234۱٬۲۳۴ ﷼

presets.accounting("USD")
// → { style: "currency", currency: "USD", currencySign: "accounting" }

Like currency but shows negative values in parentheses: (1,234.56). raqam automatically parses (...) back to a negative number.


presets.percent
// → { style: "percent" }

Formats 0.42 as "42%". Store values as decimals (0–1 range).


presets.compact
// → { notation: "compact" }

Short compact notation: 1,200,000"1.2M".


presets.compactLong
// → { notation: "compact", compactDisplay: "long" }

Long compact notation: 1,200,000"1.2 million".


presets.scientific
// → { notation: "scientific" }

Scientific notation: 1234567"1.234567E6".


presets.engineering
// → { notation: "engineering" }

Engineering notation (exponent always a multiple of 3): 12345"12.345E3".


presets.integer
// → { maximumFractionDigits: 0 }

No decimal places. 1234.5"1,235" (rounds).


presets.financial
// → { minimumFractionDigits: 2, maximumFractionDigits: 2 }

Always two decimal places. Combine with fixedDecimalScale prop to force 0.00 when empty.


presets.unit("kilometer")
// → { style: "unit", unit: "kilometer" }

Unit formatting. Any CLDR unit identifier works: "kilometer", "liter", "celsius", "kilometer-per-hour", etc.

Presets are plain objects — spread them to override:

// Compact currency (not standard but possible)
const compactCurrency = {
...presets.compact,
style: "currency" as const,
currency: "USD",
};