NumberFormatter

A wrapper around Intl.NumberFormat providing additional options, polyfills, and caching for performance.

installyarn add @internationalized/number
version3.0.6
usageimport {NumberFormatter} from '@internationalized/number'

Introduction#


NumberFormatter is a wrapper around the native Intl.NumberFormat API. It exposes the same API, but works around several browser bugs and provides polyfills for newer features. These are currently:

  • A polyfill for the signDisplay option.
  • A polyfill for the unit style, currently only for the degree unit in the narrow style

See the MDN docs for full details on how to use the API.

Interface#


MethodDescription
constructor( (locale: string, , options: NumberFormatOptions )): void
format( (value: number )): stringFormats a number value as a string, according to the locale and options provided to the constructor.
formatToParts( (value: number )): Intl.NumberFormatPart[]Formats a number to an array of parts such as separators, digits, punctuation, and more.
resolvedOptions(): Intl.ResolvedNumberFormatOptionsReturns the resolved formatting options based on the values passed to the constructor.