NumberFormatter

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

installyarn add @internationalized/number
version3.3.0
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.
formatRange( (start: number, , end: number )): stringFormats a number range as a string.
formatRangeToParts( (start: number, , end: number )): NumberRangeFormatPart[]Formats a number range as an array of parts.
resolvedOptions(): Intl.ResolvedNumberFormatOptionsReturns the resolved formatting options based on the values passed to the constructor.