Skip to content

Repository files navigation

React Format Currency

React Format Currency component to format currency in an input. With a little initialization, you get instantly internationalized values in your application.

npm versionBuild Statusnpm

React versions

react-format-currencyreact
0.1.x^15.0.0-rc, ^15.0.0, ^16.0.0-rc, ^16.2.0

Features

  • Display numbers (on Input) with separators.
  • Support for 150+ countries.
  • Runs in the browser and Node.js.
  • Built on standards.

About component

This component has as main function, show the value of the currency already formatted within the input, thus making the understanding easier for the user. he component then uses the values of those props to properly format the passed values. Below is a listing of each component, its props and a usage example. This component uses as base another component React-intl that provides React components and an API to format dates, numbers, and strings, including pluralization and handling translations.

Usage / Instalation

  1. npm install react-format-currency --save
  2. In your application add support to react-intl:
importReactfrom"react";importReactDOMfrom"react-dom";importAppfrom"./App";import{IntlProvider,addLocaleData}from'react-intl';importptfrom'react-intl/locale-data/pt';importenfrom'react-intl/locale-data/en';addLocaleData([...pt, ...en]);ReactDOM.render(<IntlProviderlocale="pt"><App/></IntlProvider>,document.getElementById("root"));
  1. To use the component:
importReact,{Component}from'react';importFormatCurrencyfrom'react-format-currency';classAppextendsComponent{render(){return(<divclassName="App"><FormatCurrencycurrency="EUR"placeholder="0.00"className="new-class-name"value={1000}disabled={true}onChange={(values)=>console.log('values: ',values)}/></div>);}}exportdefaultApp;

Props

PropsOptionsDefaultDescription
currencyEx: USD, EUR, GBP, BRL etc...requiredInternational Organization for Standardization publishes a list of standard currency codes referred to as the ISO 4217 code list.
placeholderEx: 0.00, €150.00, US$150,00 etc ...optionalThe placeholder attribute specifies a short hint that describes the expected value of an input field (e.g. a sample value or a short description of the expected format).
classNamestringoptionalBase CSS class and prefix for the component. Generally one should only change className to provide new, CSS styles for a component.
disabledbooloptionalEnable or disable input
valueEx. 1000optionalValue to the number format. It can be a float number, or formatted string.
onChangeEx: (values) => {}noneonChange handler to get values object for usage in your component.

values object

values object is on following format

{
floatValue: 1000// floating point representation.formattedValue: '€1.000,00',//value after applying formatting.value: '1000.00',//non formatted value as numeric string 1000.00.}

Contribute

Let's make React Format Currency better! If you're interested in helping, all contributions are welcome and appreciated.

About

React Format Currency component to format currency in an input.

Resources

Stars

5 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages