React-number-format: ThousandSeparator with leading zeros

Created on 6 Mar 2019  路  5Comments  路  Source: s-yadav/react-number-format

The thousandSeparator is also added if your number starts with leading zeros. Consider the following (standard) configuration:

<NumberFormat thousandSeparator="," decimalSeparator="." />

When you enter 0123 it will be displayed as 0,123

The problem that arises with this is that we have some users who want to enter a decimal point as a comma (,). So you type:

  • 0: The field now shows 0
  • ,: The field still shows 0
  • 1: The field shows 01
  • 2: The field shows 012
  • 3: The field now shows 0,123

If you don't pay close attention, you get the feeling that you correctly entered 0.123. Only after the next blur event, you will see that you actually entered 123.

So the question is: Would it be possible to only append the thousandSeparator in places where the value is _actually_ bigger than a thousand, discounting leading zeros?

That would mean that 0123 would be displayed as 0123 rather than 0,123.

Frankly, it seems to work for numbers with more than 4 characters, as 01234 is correctly displayed as 01,234.

bug

Most helpful comment

In npm it was already there. Added it on releases as well.

All 5 comments

Here is a codeSandbox that shows the output:

https://codesandbox.io/s/q5v85j32j

If you enter 0123, you get:

screenshot 2019-03-06 at 11 15 10

If you enter 000000123, you can also see two unneeded thousandSeparators:

screenshot 2019-03-06 at 11 15 33

Agree, The thousand separator should ignore leading zeros. Will fix this.

Thanks a lot for fixing this 馃檹 ! When can we expect release 4.0.7?

In npm it was already there. Added it on releases as well.

I was just going to ask a question about this 馃槃

Was this page helpful?
0 / 5 - 0 ratings