ant-design/components/input-number/demo/formatter.md

43 lines
875 B
Markdown
Raw Normal View History

---
order: 4
title:
2019-05-07 14:57:32 +08:00
zh-CN: 格式化展示
en-US: Formatter
---
## zh-CN
通过 `formatter` 格式化数字,以展示具有具体含义的数据,往往需要配合 `parser` 一起使用。
## en-US
Display value within it's situation with `formatter`, and we usually use `parser` at the same time.
2019-05-07 14:57:32 +08:00
```jsx
import { InputNumber } from 'antd';
function onChange(value) {
console.log('changed', value);
}
ReactDOM.render(
2017-03-16 16:59:06 +08:00
<div>
<InputNumber
defaultValue={1000}
formatter={value => `$ ${value}`.replace(/\B(?=(\d{3})+(?!\d))/g, ',')}
parser={value => value.replace(/\$\s?|(,*)/g, '')}
onChange={onChange}
/>
<InputNumber
defaultValue={100}
min={0}
max={100}
formatter={value => `${value}%`}
parser={value => value.replace('%', '')}
onChange={onChange}
/>
2018-06-27 15:55:04 +08:00
</div>,
2019-05-07 14:57:32 +08:00
mountNode,
2018-11-28 15:00:03 +08:00
);
2019-05-07 14:57:32 +08:00
```