Reputation: 401
I have an input that has a formatter to add a dot after every three numbers, but I need to make it a flot with a comma before the last two numbers. Right now, my code is like this, but I don't know how to put the comma before the last two digits.
<InputNumber
formatter={value => String(value).replace(/\D/g, '').split(/(?=(?:\d{3})*$)/g).join('.')}
max={1000000}
parser={value => String(value).replace(/\D/g, '')}
style={{ width: '100%' }}
/>
The output is 2.000 for example, but I need it to be 2.000,00
Upvotes: 0
Views: 617
Reputation: 2375
you can use Intl.NumberFormat API of browser. the Format you want that is use for Italy and some other europian country.
e.g. new Intl.NumberFormat('IT', {minimumFractionDigits: 2}).format('100000')
<InputNumber
formatter={value => new Intl.NumberFormat('IT', {minimumFractionDigits: 2}).format(value)}
max={1000000}
parser={value => String(value).replace(/\D/g, '')}
style={{ width: '100%' }}
/>
Upvotes: 2