useFormatNumber

useFormatNumber is a custom hook for formatting numbers.

1,234,567.89

Usage

import { useFormatNumber } from "@yamada-ui/react"
const formattedValue = useFormatNumber(1234567.89)

It formats numbers according to the specified locale and options. The hook returns the formatted value directly.

Changing the Locale

To change the locale, set a value for locale.

en-US

1,234,567.89

ja-JP

1,234,567.89

de-DE

1.234.567,89

fr-FR

1 234 567,89

zh-CN

1,234,567.89

Set the Locale for the Entire Application

If you want to set the locale for the entire application, set the locale for the UIProvider.

import { UIProvider } from "@yamada-ui/react"

const App = () => {
  return (
    <UIProvider locale="en-US">
      <YourComponent />
    </UIProvider>
  )
}

Converting to Currency

To convert to currency, set "currency" for style.

USD

$1,234,567.89

EUR

1.234.567,89 €

JPY

ï¿¥1,234,568

Converting to Units

To convert to units, set "unit" for style.

100 kg

100 degrees Celsius

100km/h

Converting to Percent

To convert to percent, set "percent" for style.

45%

45.00%

Converting Notation

To convert notation, set a value for notation.

1,234,567.89

1.235E6

1.235E6

1.2M

Controlling Decimal Places

To control the number of decimal places, use minimumFractionDigits and maximumFractionDigits.

1,234.50

1,234.567

1,234.0000

Disabling Grouping

To disable grouping, set false for useGrouping.

1234567.89

Changing the Sign Display

To change the sign display, set a value for signDisplay.

+1,234.5

-1,234.5