Skip to main content

intlNumberFormatter

A thin wrapper around numberFormatter that uses locales to deduce the formatting.

const formattedInput = useFormattedInput(
intlNumberFormatter({
locales: "en-US",
})
)
Value: 1234

Controlled value

value

Type: number | null
Default: null

Value of the input.

onChange

Type: (value: number | null, formattedValue: string) => void
Default: undefined

The onChange callback is called when the value changes. It receives both the formattedValue and the value.

liveUpdate

Type: boolean
Default: false

When false (default value), the onChange callback is only called on blur for improved performance. If yo need the onChange callback to be called each time the user types a character, pass true.

Decimals

maxDecimals

Type: number
Default: Infinity

Defines the maximum number of decimals allowed.

minDecimals

Type: number
Default: 0

Defines the minimum number of decimals, zeros will be added at the end if needed.

scale

Type: number
Default: 0

Defines the number of places to move the decimals by, can be positive or negative, a value of zero has no effect.

Format

locales

Type: string | string[]
Default: undefined

A locale to use to deduce formatting from. Supports the same locales as Intl.

prefix

Type: string
Default: ''

Defines the string that should appear before the input.

suffix

Type: string
Default: ''

Defines the string that should appear after the input.

Constraints

max

Type: number
Default: Infinity

Defines the maximum allowed value.

min

Type: number
Default: -Infinity

Defines the minimum allowed value.