Numeral-js icon indicating copy to clipboard operation
Numeral-js copied to clipboard

Allow multiple decimal delimiters

Open mcorteel opened this issue 8 years ago • 6 comments

I think that was the actual problem in #226, but here it is: all languages that use a comma as a decimal delimiter still have keyboards where the num pad contains a point instead of a comma.

So when inputting values, most people still write "1.3" instead of the canonical "1,3". So both should be considered OK. This is the case for French and German.

Would it be possible to have multiple decimal delimiters (for example with an array instead of a string in the locale configuration)?

mcorteel avatar Mar 24 '17 12:03 mcorteel

If there are keyboards in the wild which claim to have a German layout but have a point instead of a comma on the numeric keypad, then I'd say their claim is simply wrong.

Nevertheless, the resulting character is dependent on the language settings of the system, not the label of the key.

xehpuk avatar May 23 '17 18:05 xehpuk

Sorry about the German keyboard, you're right.

Nevertheless, the resulting character is dependent on the language settings of the system, not the label of the key.

I don't understand what you mean. On a French keyboard layout, the point in the num pad results in a point, at least on all of the layouts I have ever used on any GNU/Linux distributions (and I'm pretty sure that it's the same for other OSes). This is weird and pretty stupid, but this is also a problem that might be solved with my suggestion. The point doesn't conflict with other characters in French, since the thousands separator is a space (and BTW, this is yet another complicated case because the thousands separator is only used if the number has 5 digits, not 4 but this is not as important).

mcorteel avatar May 24 '17 05:05 mcorteel

On my German keyboard, the numpad comma results in a comma for the "de-DE" system locale and in a point for the "en-US" system locale (and in a point for the "fr-FR" system locale) on Windows 10.

xehpuk avatar May 24 '17 11:05 xehpuk

So anyway, what can be done about that?

mcorteel avatar May 24 '17 11:05 mcorteel

This is actually a common problem on mobile android devices prior to android 8. The numerical input is often prompting the keyboard with . instead of , even though the system locale is for example de-DE.

This would be a really nice thing to have.

JohannesHome avatar Aug 21 '17 13:08 JohannesHome

I discovered this thread just now. I have the same use case with a french client whose numpad decimal separator outputs a '.' instead of a ','. My solution (which is not necessary applicable to everyone) was to add in my french locale file a small function to modify the value before passing it to the format function. In that function, I just replace '.' by ',':

var numeralLocale = { delimiters: { thousands: ' ', decimal: ',' }, abbreviations: { thousand: 'k', million: 'm', billion: 'b', trillion: 't' }, ordinal : function (number) { return number === 1 ? 'er' : 'e'; }, currency: { symbol: '€' }, preValue: function(v) { return v.toString().replace('.',',') } }

and before formatting a number (in a custom number field for me), I call this function if it exists: let preValue = numeral.localeData().preValue || function(v) {return v}; numeral(preValue(v)).value();

It's a bit more verbose but it works as intended and has the advantage of being handled by locale...

gama410 avatar Jan 26 '22 15:01 gama410