Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

InputNumber for a currency input?

Tags:

antd

I need a currency amount input. Is there anyway to customize the InputNumber to support things like commas (',') or $?

Similar to these:

http://leonardowf.github.io/react-simple-currency/

https://github.com/jsillitoe/react-currency-input

I'm using form and InputNumber right now but it is hard to read (for the user) without at least the commas per thousand:

<Col span='24'>
   <FormItem label='Original Investment'>
         {getFieldDecorator('originalInvestment', {
           rules: [{ required: true, message: 'Please input your Investment!' }],
           initialValue: 100000000
         })(
            <InputNumber min={100000000} max={10000000000} />
         )}
   </FormItem>
</Col>
like image 864
arcom Avatar asked Jun 13 '26 06:06

arcom


1 Answers

you can use the formatter property to achieve this

<InputNumber
  defaultValue={1000}
  formatter={value => `$ ${value}`.replace(/\B(?=(\d{3})+(?!\d))/g, ',')}
  parser={value => value.replace(/\$\s?|(,*)/g, '')}
  onChange={onChange}
/>

check https://ant.design/components/input-number/#components-input-number-demo-formatter for more

like image 125
Mayomi Ayandiran Avatar answered Jun 18 '26 00:06

Mayomi Ayandiran



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!