Skip to content

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

Closed
react-component/input-number
#279

Description

@xuqiang1227
  • 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

Activity

  1. afc163 commented on Nov 28, 2020

    @afc163
    Member

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

  2. xuqiang1227 commented on Nov 30, 2020

    @xuqiang1227
    Author

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

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

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

    inputDisplayValueFormat = inputDisplayValueFormat
            .toString()
            .replace(/(.*)\./, `$1${this.props.decimalSeparator}`);
    
  3. yoyo837 commented on Nov 30, 2020

    @yoyo837
    Contributor

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

  4. afc163 commented on Nov 30, 2020

    @afc163
    Member

    来个 PR 吧。

    @xuqiang1227

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions