useNumberFormat

NumberFormat
stable

Wraps Intl.NumberFormat with an LRU cache, reactive locale resolution, and high-level format dialects (currency, percent, unit, compact, scientific, engineering). Accepts options as plain objects, refs, or getter functions. Used by OrigamNumberFormat and usable standalone in Pinia stores or server-side rendering contexts.

API

Signature

Full TypeScript signature sourced from the composable file.

typescript

Consumed interfaces

IUseNumberFormatOptions

API

Parameters

Input parameters accepted by this composable.

options
MaybeRefOrGetter<IUseNumberFormatOptions>
{}
Formatting options: locale (string | string[] | "auto"), format ("decimal" | "currency" | "percent" | "unit" | "compact" | "scientific" | "engineering"), currency, unit, notation, minimumFractionDigits, maximumFractionDigits, useGrouping, signDisplay, and more. Accepts a plain object, a ref, or a getter.

API

Return values

Properties and methods exposed by the composable return object.

intl
The resolved Intl.NumberFormat instance (LRU-cached). Recomputed only when locale or options change.
format
Formats a number or numeric string to a localised string. Non-finite strings are coerced to 0 rather than producing "NaN".
formatToParts
Returns the formatted parts array (integer, decimal, fraction, currency, …) for custom rendering, e.g. styling the currency symbol differently.

Usage

Examples

Ready-to-paste usage snippets.

Currency formatting (French euros)

vue

Reactive compact notation

vue

Via OrigamNumberFormat component

vue