Numeral-js
Numeral-js copied to clipboard
Allow multiple decimal delimiters
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)?
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.
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).
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.
So anyway, what can be done about that?
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.
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...