Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

react-currency-input-field

cchanxzy1.2mMIT4.0.3TypeScript support: included

React <input/> component for formatting currency and numbers.

react, component, currency, form, field, number, input, intl, locale

readme

React Currency Input Field Component

npm npm NPM Codecov Coverage Release build

Features

Examples

Play with demo or view examples code

React Currency Input Demo

Install

npm install react-currency-input-field

yarn add react-currency-input-field

pnpm add react-currency-input-field

Usage

import CurrencyInput from 'react-currency-input-field';

<CurrencyInput
  id="input-example"
  name="input-name"
  placeholder="Please enter a number"
  defaultValue={1000}
  decimalsLimit={2}
  onValueChange={(value, name, values) => console.log(value, name, values)}
/>;

See src/examples for more patterns covering implementation details and validation helpers.

Props

Name Type Default Description
allowDecimals boolean true Allow entering decimal values.
allowNegativeValue boolean true Allow the user to enter negative numbers.
className string | Additional CSS class names for the rendered input.
customInput React.ElementType input Render a custom component instead of the native input.
decimalsLimit number 2 Maximum number of fractional digits the user can type.
decimalScale number | Pads or trims decimals on blur to the specified length.
decimalSeparator string locale default Character used to separate the integer and fractional parts. Cannot be numeric or match the group separator.
defaultValue number | string | Initial value when the component is uncontrolled.
value number | string | Controlled value supplied by the parent component.
disabled boolean false Disable user interaction.
disableAbbreviations boolean false Disable shorthand parsing (1k, 2m, 3b, etc.).
disableGroupSeparators boolean false Prevent automatic insertion of group separators (e.g. keep 1000 instead of 1,000).
fixedDecimalLength number | Forces the value to always display with the specified number of decimals on blur.
formatValueOnBlur boolean true When set to false, the onValueChange will not be called on blur events.
groupSeparator string locale default Character used to group thousands. Cannot be numeric.
id string | Forwarded to the rendered input element.
intlConfig IntlConfig | Locale configuration for Intl.NumberFormat (locale, currency, style).
maxLength number | Maximum number of characters (excluding the negative sign) the user can enter.
onValueChange function | Handler fired whenever the parsed value changes.
placeholder string | Displayed when there is no value.
prefix string | String added before the value (e.g. £, $). Overrides locale-derived prefixes.
suffix string | String added after the value (e.g. %, ). Overrides locale-derived suffixes.
step number | Increment applied when pressing ArrowUp / ArrowDown.
transformRawValue function | Intercept and adjust the raw input string before parsing. Must return a string.

onValueChange

Handle changes to the value.

onValueChange = (value, name, values) => void;

value

value will give you the value in a string format, without the prefix/suffix/separators.

Useful for displaying the value, but you can use values.float if you need the numerical value for calculations.

Example: £123,456 -> 123456

name

name is the name you have passed to your component

values

values gives an object with three key values:

  • float: Value as float or null if empty. Example: "1.99" > 1.99
  • formatted: Value after applying formatting. Example: "1000000" > "1,000,0000"
  • value: Non formatted value as string, ie. same as first param.

Abbreviations

It can parse values with abbreviations k, m and b

Examples:

  • 1k = 1,000
  • 2.5m = 2,500,000
  • 3.456B = 3,456,000,000

This can be turned off by passing in disableAbbreviations={true}.

Prefix and Suffix

You can add a prefix or suffix by passing in prefix or suffix.

import CurrencyInput from 'react-currency-input-field';

<CurrencyInput prefix="£" value={123} />;
// £123

<CurrencyInput suffix="%" value={456} />;
// 456%

Note: Passing in prefix/suffix will override the intl locale config.

Separators

You can change the decimal and group separators by passing in decimalSeparator and groupSeparator.

Example:

import CurrencyInput from 'react-currency-input-field';

<CurrencyInput decimalSeparator="," groupSeparator="." />;

Note: the separators cannot be a number, and decimalSeparator must be different to groupSeparator.

To turn off auto adding the group separator, add disableGroupSeparators={true}.

Intl Locale Config

This component can also accept international locale config to format the currency to locale setting.

Examples:

import CurrencyInput from 'react-currency-input-field';

// US Dollar
<CurrencyInput intlConfig={{ locale: 'en-US', currency: 'USD' }} />

// British Pound
<CurrencyInput intlConfig={{ locale: 'en-GB', currency: 'GBP' }} />

// Canadian Dollar
<CurrencyInput intlConfig={{ locale: 'en-CA', currency: 'CAD' }} />

// Australian Dollar
<CurrencyInput intlConfig={{ locale: 'en-AU', currency: 'AUD' }} />

// Japanese Yen
<CurrencyInput intlConfig={{ locale: 'ja-JP', currency: 'JPY' }} />

// Chinese Yuan
<CurrencyInput intlConfig={{ locale: 'zh-CN', currency: 'CNY' }} />

// Euro (Germany)
<CurrencyInput intlConfig={{ locale: 'de-DE', currency: 'EUR' }} />

// Euro (France)
<CurrencyInput intlConfig={{ locale: 'fr-FR', currency: 'EUR' }} />

// Indian Rupee
<CurrencyInput intlConfig={{ locale: 'hi-IN', currency: 'INR' }} />

// Brazilian Real
<CurrencyInput intlConfig={{ locale: 'pt-BR', currency: 'BRL' }} />

locale should be a BCP 47 language tag, such as "en-US" or "en-IN".

currency should be a ISO 4217 currency code, such as "USD" for the US dollar, "EUR" for the euro, or "CNY" for the Chinese RMB.

Any prefix, suffix, group separator and decimal separator options passed in will override the default locale settings.

Decimal Scale and Decimals Limit

decimalsLimit and decimalScale sound similar but have different usages.

decimalsLimit prevents the user from typing more than the limit, and decimalScale will format the decimals onBlur to the specified length, padding or trimming as necessary.

Example:

If decimalScale is 2

- 1.5 becomes 1.50 (padded)
- 1.234 becomes 1.23 (trimmed)

---

If decimalLimit is 2

- User enters 1.23
- User is then prevented from entering another value

Fixed Decimal Length

Use fixedDecimalLength so that the value will always have the specified length of decimals.

This formatting happens onBlur.

Example if fixedDecimalLength was 2:

- 1 -> 1.00
- 123 -> 1.23
- 12.3 -> 12.30
- 12.34 -> 12.34

Format values for display

Use the formatValue function to format the values to a more user friendly string. This is useful if you are displaying the value somewhere else ie. the total of multiple inputs.

import { formatValue } from 'react-currency-input-field';

// Format using prefix, groupSeparator and decimalSeparator
const formattedValue1 = formatValue({
  value: '123456',
  groupSeparator: ',',
  decimalSeparator: '.',
  prefix: '$',
});

console.log(formattedValue1);
// $123,456

// Format using intl locale config
const formattedValue2 = formatValue({
  value: '500000',
  intlConfig: { locale: 'hi-IN', currency: 'INR' },
});

console.log(formattedValue2);
// ₹5,00,000

Issues

Feel free to raise an issue on Github if you find a bug or have a feature request.

Contributing

If you would like to contribute to this repository, please refer to the contributing doc.

Support this Project

If you'd like to support this project, please refer to the support doc.

v4.0.0 Announcement

I'm excited to announce the release of v4.0.0.

This marks the beginning of development for version 4.0.0, and the first improvement is a significant reduction in bundle size, going from ~26KB to ~7.6kB (Minified), 3.1kB (Minified + Gzipped)

For more information, please refer to the announcement post.

changelog

4.0.3 (2025-09-29)

Bug Fixes

  • esm: bundle ESM/CJS builds to avoid Node ESM resolution issues in SSR (81d6b94)

4.0.2 (2025-09-24)

4.0.1 (2025-09-17)

4.0.0 (2025-09-17)

  • build!: switch from rollup to esbuild to build (75ef80c)

Bug Fixes

  • correct entry for cjs and esm (cc48412)

Features

  • merge changes in main into alpha branch (6985156)

BREAKING CHANGES

  • UMD is no longer exported.

In order to reduce complexity and simplify the build process, we have switched from rollup to esbuild and only export CJS and ESM versions.

This means that the UMD build is no longer exported.

4.0.0-alpha.3 (2025-02-22)

Bug Fixes

  • add react 19 as peer dependency (396d57b), closes #380
  • handle cases where decimalSeparator is empty (#385) (656e5c2)

Features

  • intlConfig support all NumberFormatOptions (#386) (0b84349)
  • merge changes in main into alpha branch (6985156)

3.10.0 (2025-02-22)

Features

  • intlConfig support all NumberFormatOptions (#386) (0b84349)

3.9.2 (2025-02-22)

Bug Fixes

  • handle cases where decimalSeparator is empty (#385) (656e5c2)

3.9.1 (2025-02-22)

Bug Fixes

  • add react 19 as peer dependency (396d57b), closes #380

4.0.0-alpha.2 (2024-11-12)

Bug Fixes

  • correct entry for cjs and esm (cc48412)

Features

4.0.0-alpha.1 (2024-11-09)

  • build!: switch from rollup to esbuild to build (75ef80c)

BREAKING CHANGES

  • UMD is no longer exported.

In order to reduce complexity and simplify the build process, we have switched from rollup to esbuild and only export CJS and ESM versions.

This means that the UMD build is no longer exported.

3.9.0 (2024-11-12)

Features

3.8.1 (2024-11-10)

3.8.0 (2024-02-22)

Features

3.7.1 (2024-02-19)

Bug Fixes

  • update doc to trigger release (4672670)

3.7.0 (2024-02-11)

Features

  • export utility function 'cleanValue' (#334) (026329f)

3.6.14 (2023-12-29)

Bug Fixes

  • export type CurrencyInputOnChangeValues and update examples (#331) (8ea2c47)

3.6.13 (2023-12-28)

Bug Fixes

  • Update input to empty string when userValue is undefined (#323) (30c5fcc)

3.6.12 (2023-11-07)

Bug Fixes

  • fixedDecimalValue issue #292 and handle fixedDecimalValue 0 (#313) (5be14cb)

3.6.11 (2023-06-23)

Bug Fixes

3.6.10 (2023-02-03)

Bug Fixes

  • closes Cursor jumping issue if the ref passed isn't a ref object #247 (#276) (ef4e9e4)

3.6.9 (2022-10-25)

3.6.8 (2022-10-20)

Bug Fixes

  • parse float for currencies w/o decimal sep (#259) (a75d8cc)

3.6.7 (2022-10-18)

Bug Fixes

  • safari cursor stuck if onBlur & decimalScale set (#261) (d724157)

3.6.6 (2022-10-18)

Bug Fixes

  • no decimals if defined decimalScale, input value as X.00 and intlConfig, but without no currency (#262) (36ad0ed)

3.6.5 (2022-09-20)

Bug Fixes

3.6.4 (2022-01-14)

Bug Fixes

3.6.3 (2022-01-09)

Bug Fixes

3.6.2 (2022-01-09)

Bug Fixes

  • dont block controlled prop if decimal separator not present (#215) (02b875c)

3.6.1 (2022-01-09)

Bug Fixes

3.6.0 (2021-10-27)

Features

  • add transformRawValue option to transform the value before parsing (#208) (36950cc)

3.5.1 (2021-09-01)

3.5.0 (2021-08-30)

Features

  • onValueChange calls Values object as third param (#199) (f2f6f2b)

3.4.3 (2021-08-22)

Bug Fixes

  • artificial change to trigger version update (1dfc138)

3.4.2 (2021-07-08)

Performance Improvements

3.4.1 (2021-05-22)

Bug Fixes

3.4.0 (2021-05-22)

Features

3.3.2 (2021-04-13)

Bug Fixes

  • prevent cursor jumping when press delete key (#155) (242ec90)

3.3.1 (2021-03-21)

Bug Fixes

  • handle intl config with prefix and negative (#148) (0c9e6ec)

3.3.0 (2021-02-18)

Features

3.2.5 (2021-02-15)

3.2.4 (2021-02-03)

Bug Fixes

  • remove prefix if letters (7958f29)

3.2.3 (2021-01-31)

Bug Fixes

  • prevent cursor moving if only negative value at start (aadec9d)

3.2.2 (2021-01-25)

Bug Fixes

  • intl config currency is optional (a52a9d6)

3.2.1 (2021-01-24)

3.2.0 (2021-01-24)

Features

  • stepping does not go beyond min max values (0cc5d57)

3.1.0 (2021-01-24)

Features

  • allow custom suffix prop (9b57ec6)

3.0.4 (2021-01-24)

Bug Fixes

  • prevent autofocusing on load (da10c81)

3.0.3 (2021-01-18)

Bug Fixes

  • formatValue trim decimalScale (012d4c2)

3.0.2 (2021-01-08)

Bug Fixes

  • default value with decimal scale renders correctly part 2 (4b7f5db)

3.0.1 (2021-01-07)

Bug Fixes

  • default value with decimal scale renders correctly (c225306)

3.0.0 (2021-01-05)

Bug Fixes

  • fixed a few inconsistencies and added intl config to examples (796e623)

Features

  • add intl locale config option (e119352)
  • allow customInput prop (f372201)
  • depreciate onBlurValue prop (8651e76)
  • handle backspace with suffix (fc84301)
  • renamed onChange prop to onValueChange (83d3806)
  • renamed precision to decimalScale (c545b78)
  • renamed turnOffAbbreviations to disableAbbreviations (7751a43)
  • renamed turnOffSeparators to disableGroupSeparators (b16f577)
  • wrap component in forwardRef (3a1f5bc)

BREAKING CHANGES

  • "onBlurValue" no longer supported
  • Renamed "onChange" to "onValueChange"
  • Renamed "turnOffAbbreviations" to "disableAbbreviations"
  • Renamed "turnOffSeparators" to "disableGroupSeparators"
  • renamed precision to decimalScale
  • Using Intl.NumberFormat to format value
  • can pass in component ref

3.0.0-beta.11 (2021-01-04)

3.0.0-beta.10 (2021-01-02)

Features

3.0.0-beta.9 (2021-01-02)

Bug Fixes

  • fixed a few inconsistencies and added intl config to examples (796e623)

3.0.0-beta.8 (2021-01-02)

Features

  • handle backspace with suffix (fc84301)

3.0.0-beta.7 (2020-12-10)

3.0.0-beta.6 (2020-12-10)

3.0.0-beta.5 (2020-12-09)

Features

  • depreciate onBlurValue prop (8651e76)

BREAKING CHANGES

  • "onBlurValue" no longer supported

3.0.0-beta.4 (2020-12-09)

Features

  • renamed onChange prop to onValueChange (83d3806)

BREAKING CHANGES

  • Renamed "onChange" to "onValueChange"

3.0.0-beta.3 (2020-12-06)

Features

  • renamed precision to decimalScale (c545b78)
  • renamed turnOffAbbreviations to disableAbbreviations (7751a43)
  • renamed turnOffSeparators to disableGroupSeparators (b16f577)

BREAKING CHANGES

  • Renamed "turnOffAbbreviations" to "disableAbbreviations"
  • Renamed "turnOffSeparators" to "disableGroupSeparators"
  • renamed precision to decimalScale

3.0.0-beta.2 (2020-12-03)

Features

  • add intl locale config option (e119352)

BREAKING CHANGES

  • Using Intl.NumberFormat to format value

3.0.0-beta.1 (2020-11-19)

Features

  • wrap component in forwardRef (3a1f5bc)

BREAKING CHANGES

  • can pass in component ref

    2.7.1 (2020-12-10)

2.7.0 (2020-11-18)

Features

  • can turn off abbreviations (67a54c1)

2.6.0 (2020-11-15)

Features

  • handle arrow down and arrow up step changes (31e6156)

2.5.0 (2020-11-11)

Features

  • export format value function and add to readme (cad0b95)

2.4.1 (2020-11-04)

Bug Fixes

  • add onChange to onBlur test (4195ef6)

2.4.0 (2020-11-03)

Features

2.3.6 (2020-11-03)

Bug Fixes

2.3.5 (2020-10-28)

Bug Fixes

  • handle values before prefix (942a613)

2.3.4 (2020-10-24)

Bug Fixes

  • refactored isNumber function (68640ff)

2.3.3 (2020-10-10)

Bug Fixes

  • allows default 0 value (4189b80)
  • disallow invalid chars and updated examples (134d36a)
  • don't call onChange with only - (ef4101b)

2.3.2 (2020-09-27)

Bug Fixes

2.3.1 (2020-09-25)

Bug Fixes

  • can clear field programmatically (2598c16)

2.3.0 (2020-09-20)

Features

  • add prop to disallow negative value (b9ef02c)

2.2.0 (2020-08-25)

Features

  • add props decimalSeparator and groupSeparator (bb4459b)
  • can use any string as a separator (c84b1cd)
  • fixed decimal length prop (f3f50a1)
  • handle negative values (b505e4c)

2.2.0-beta.3 (2020-08-25)

Features

2.2.0-beta.2 (2020-08-20)

Features

  • fixed decimal length prop (7089248)

2.2.0-beta.1 (2020-08-14)

Features

  • add props decimalSeparator and groupSeparator (344e3b0)
  • can use any string as a separator (ae5755a)

2.1.0 (2020-08-13)

Features

2.0.0 (2020-07-02)

Features

BREAKING CHANGES

  • onChange will return string or undefined rather than number or null

1.0.1 (2020-05-08)

Bug Fixes

  • artificial change to trigger version update (ae56e99)

1.0.0 (2020-05-08)

Bug Fixes

BREAKING CHANGES

  • trigger package update manually

0.10.1 (2020-05-08)

Bug Fixes

  • correct package version and update demo (20112fc)

0.10.0 (2020-05-08)

Features

  • can parse abbreviated values k, m, b (f588dcf)
  • updated examples (6a2db92)

0.9.0 (2020-05-08)

Features

  • allow props for input to be passed (998c3ae)

0.8.4 (2020-05-06)

Bug Fixes

0.8.3 (2020-05-06)

Bug Fixes

0.8.2 (2020-04-23)

Bug Fixes

  • add inputmode and remove pattern (de16a2e)
  • upgrade dependencies (d258747)

0.8.1 (2020-04-18)

Bug Fixes

0.8.0 (2020-04-13)

Features

0.7.0 (2020-04-10)

Features

  • allow input to be disabled (c6881c2)

0.6.0 (2020-03-08)

Features

0.5.3 (2019-12-08)

Bug Fixes

0.5.2 (2019-12-01)

Bug Fixes

  • cursor jumping when modifying value (db449d6)
  • react is specified as external, and pattern allows float on mobile (c011361)

0.5.1 (2019-11-30)

Bug Fixes

  • modify typescript config to correctly output types (#19) (392082e)

0.5.0 (2019-11-30)

Features

  • allow name to be added to prop and onChange callback (#17) (25ae63c)

Changelog

All notable changes to this project will be documented in this file. See standard-version for commit guidelines.

0.3.1 (2019-11-21)

0.3.0 (2019-11-21)

Features

  • can set default value and decimals (#8) (54b2d4b)

0.2.1 (2019-11-21)

Features

  • can set default value and decimals (#8) (54b2d4b)

0.2.0 (2019-09-08)

⚠ BREAKING CHANGES

  • removed limit prop

  • chore: updated workflow

  • Feat/remove limit update with hooks (#5) (a3463bd), closes #5

Bug Fixes

0.1.0 (2019-09-08)

⚠ BREAKING CHANGES

  • removed limit prop

  • chore: updated workflow

  • Feat/remove limit update with hooks (#5) (a3463bd), closes #5

Bug Fixes

0.0.47 (2019-09-08)

0.10.0 (2019-09-08)

⚠ BREAKING CHANGES

  • removed limit prop

  • removed limit prop, updated tests and examples (ed24b8e)

Bug Fixes

0.1.0 (2019-09-08)

⚠ BREAKING CHANGES

  • removed limit prop

  • removed limit prop, updated tests and examples (ed24b8e)

Bug Fixes

0.0.47 (2019-09-08)

Bug Fixes

Features

  • upating tests and examples (e18c23a)

0.0.46 (2019-08-29)

Bug Fixes