最多保留2位
<InputNumber
min={-10000}
max={10000}
formatter={value => {
return (
`${value}`
.replace(/\B(?=(\d{3})+(?!\d))/g, "")
.replace(/^(-)*(\d+)\.(\d\d).*$/, "$1$2.$3") + '元'
);
}}
parser={value => {
return value
.replace(new RegExp('元', "g"), "")
.replace(new RegExp(/[^0-9.-]/, "g"), "")
.replace(/^(-)*(\d+)\.(\d\d).*$/, "$1$2.$3");
}}
placeholder='请输入'/>
最多保留3位 (以此类推)加\d
<InputNumber
min={-10000}
max={10000}
formatter={value => {
return (
`${value}`
.replace(/\B(?=(\d{3})+(?!\d))/g, "")
.replace(/^(-)*(\d+)\.(\d\d\d).*$/, "$1$2.$3") + '元'
);
}}
parser={value => {
return value
.replace(new RegExp('元', "g"), "")
.replace(new RegExp(/[^0-9.-]/, "g"), "")
.replace(/^(-)*(\d+)\.(\d\d\d).*$/, "$1$2.$3");
}}
placeholder='请输入'/>
直接使用precision
<InputNumber
min={-10000}
max={10000}
precision={2}
formatter={value => {
return (
`${value}` + '元'
);
}}
parser={value => {
return value.replace(new RegExp('元', "g"), "")
}}
placeholder='请输入'/>