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
Signature TypeScript complète extraite du fichier du composable.
Interfaces consommées
IUseNumberFormatOptions
API
Paramètres
Paramètres d'entrée acceptés par ce composable.
- optionsMaybeRefOrGetter<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
Valeurs de retour
Propriétés et méthodes exposées par l'objet retourné par le composable.
- 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
Exemples
Extraits de code prêts à coller.
Currency formatting (French euros)
Reactive compact notation
Via OrigamNumberFormat component