Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NumberInput 无法正确格式化以色列等国家的负数值 #28057

Closed
1 task
xuqiang1227 opened this issue Nov 28, 2020 · 4 comments · May be fixed by react-component/input-number#279
Closed
1 task

NumberInput 无法正确格式化以色列等国家的负数值 #28057

xuqiang1227 opened this issue Nov 28, 2020 · 4 comments · May be fixed by react-component/input-number#279

Comments

@xuqiang1227
Copy link

  • I have searched the issues of this repository and believe that this is not a duplicate.

Reproduction link

Edit on CodeSandbox

Steps to reproduce

以色列等国家的负数格式显示为:-x.xxx.xxx,xxx

也就是千分位分隔符为 ., 小数点为: ,

当输入值为 -88888888888.88 应该格式化为: -88.888.888.888,88 ,但实体上显示为: -88,888.888.888,88

格式化正则表达式为:/\B(?=(\d{3}) (?!\d))/g

What is expected?

当输入值为 -88888888888.88 应该格式化为: -88.888.888.888,88

What is actually happening?

实际上显示的为: -88,888.888.888,88

Environment Info
antd 4.8.6
React 16.14.0
System window 10
Browser chrome 87
@afc163
Copy link
Member

afc163 commented Nov 28, 2020

formatter 和 parser 完全是开发者自定义的,官方这个例子肯定不能满足所有情况,建议根据自己的需求定制修改。

@afc163 afc163 closed this as completed Nov 28, 2020
@xuqiang1227
Copy link
Author

@afc163 偏右,我查了一下代码,这个问题的原因是: 设置了 decimalSeparator = ','formatter函数将千位分隔符设置为 .
rc-input-number 代码中,直接使用

inputDisplayValueFormat = inputDisplayValueFormat
        .toString()
        .replace('.', this.props.decimalSeparator);

直接将格式化后的第一个位 .,替换成 decimalSeparator
所以这个地方,能否改为

inputDisplayValueFormat = inputDisplayValueFormat
        .toString()
        .replace(/(.*)\./, `$1${this.props.decimalSeparator}`);

@yoyo837
Copy link
Contributor

yoyo837 commented Nov 30, 2020

那只是个demo,或者你可以来PR帮忙改进一下demo

@afc163
Copy link
Member

afc163 commented Nov 30, 2020

来个 PR 吧。

@xuqiang1227

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants