2

我需要输入货币金额。无论如何自定义 InputNumber 以支持逗号(',')或 $ 之类的东西?

类似于这些:

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

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

我现在正在使用表单和 InputNumber,但是如果没有至少每千个逗号,就很难(对于用户)阅读:

<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>
4

3 回答 3

1

暂不支持,可以追踪https://github.com/ant-design/ant-design/issues/4681

于 2017-01-26T13:27:28.150 回答
1

您可以使用 formatter 属性来实现这一点

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

检查https://ant.design/components/input-number/#components-input-number-demo-formatter了解更多信息

于 2021-05-27T22:05:10.070 回答
0

使用这个库。它维护得很好,并且经过了很好的测试 https://github.com/s-yadav/react-number-format。我尝试了很多图书馆。这解决了我的问题

于 2019-03-14T23:29:28.333 回答