NumberFormatter
A wrapper around Intl.NumberFormat providing additional options, polyfills, and caching for performance.
install | yarn add @internationalized/number |
---|---|
version | 3.2.0 |
usage | import {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 thedegree
unit in thenarrow
style
See the MDN docs for full details on how to use the API.
Interface#
Method | Description |
constructor(
(locale: string,
, options: NumberFormatOptions
)): void | |
format(
(value: number
)): string | Formats 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
)): string | Formats a number range as a string. |
formatRangeToParts(
(start: number,
, end: number
)): NumberRangeFormatPart[] | Formats a number range as an array of parts. |
resolvedOptions(): Intl.ResolvedNumberFormatOptions | Returns the resolved formatting options based on the values passed to the constructor. |