diff --git a/src/index.js b/src/index.js index dcc2e8f..15eed0d 100644 --- a/src/index.js +++ b/src/index.js @@ -34,10 +34,18 @@ class FormatCurrency extends Component { const el = e.target; const inputValue = el.value; + const rawValue = (inputValue) ? removeAllButLast(inputValue.replace(/[^\d,.]/g, '').replace(',', '.'), '.') : ''; + const formattedValue = rawValue ? this.props.intl.formatNumber(rawValue, { + style: 'currency', + currency: this.props.currency, + }) : ''; + this.setState({ - value: (inputValue) ? removeAllButLast(inputValue.replace(/[^\d,.]/g, '').replace(',', '.'), '.') : '', - formattedValue: el.value, + value: rawValue, + formattedValue, }); + + el.value = formattedValue; } onFocus(e) {