Skip to content

useNumberFieldFormat

useNumberFieldFormat formats a number for display using Intl.NumberFormat. It has zero state machine overhead — ideal for price tables, dashboards, or any read-only numeric display.

import { useNumberFieldFormat } from "raqam";
// or
import { useNumberFieldFormat } from "raqam/react";
function useNumberFieldFormat(
value: number | null | undefined,
options: {
locale?: string;
formatOptions?: Intl.NumberFormatOptions;
prefix?: string;
suffix?: string;
minimumFractionDigits?: number;
maximumFractionDigits?: number;
fixedDecimalScale?: boolean;
}
): string;
ParamTypeDescription
valuenumber | null | undefinedThe value to format. Returns "" for null/undefined.
options.localestringBCP 47 locale. Defaults to the current runtime locale.
options.formatOptionsIntl.NumberFormatOptionsPassed to Intl.NumberFormat.
options.prefix / options.suffixstringAdd custom affixes around the formatted value.
options.minimumFractionDigits / options.maximumFractionDigitsnumberOverride fraction digit behavior.
options.fixedDecimalScalebooleanForces maximumFractionDigits trailing zeros.

A formatted string, or "" when value is null/undefined/NaN.

import { useNumberFieldFormat } from "raqam";
function PriceTag({ amount }: { amount: number }) {
const formatted = useNumberFieldFormat(amount, {
locale: "en-US",
formatOptions: { style: "currency", currency: "USD" },
});
return <span>{formatted}</span>;
}
// "en-US" + USD → "$1,234.56"
// "de-DE" + EUR → "1.234,56 €"
// "fa-IR" + IRR → "۱٬۲۳۴٫۵۶ ﷼"

For React Server Components or SSR, import from raqam/server (zero React dependency):

import { createFormatter } from "raqam/server";
const formatter = createFormatter({
locale: "en-US",
formatOptions: { style: "currency", currency: "USD" },
});
const html = `<span>${formatter.format(1234.56)}</span>`;
// "$1,234.56"
const items = [
{ name: "MacBook Pro", price: 2499 },
{ name: "iPhone 15 Pro", price: 1199 },
{ name: "AirPods Pro", price: 249 },
];
function PriceTable() {
return (
<table>
{items.map((item) => (
<PriceRow key={item.name} {...item} />
))}
</table>
);
}
function PriceRow({ name, price }: { name: string; price: number }) {
const formatted = useNumberFieldFormat(price, {
locale: "en-US",
formatOptions: { style: "currency", currency: "USD" },
});
return (
<tr>
<td>{name}</td>
<td style={{ textAlign: "right", fontVariantNumeric: "tabular-nums" }}>
{formatted}
</td>
</tr>
);
}
useNumberFieldFormatNumberField.Formatted
Use caseAny component, standalone displayInside a NumberField.Root
Requires stateNoYes (reads from context)
Reflects user editsNoYes (live updates with input)