Open asagrawal opened 10 years ago
It seems that the bug is because the de language "delimiters" are setup as: delimiters: { thousands: ' ', decimal: ',' }
The thousands part should be a "." and not a " " from what i understand. Any thoughts?
Yes, the thousands delimiter should be a '.', not a ' '.
Actually, no, the space is not incorrect. You can use both in German typograhpy.
OK, I agree. The DIN 1333 standard does specify both. I was actually surprised that it favours the space over the dot thousands delimiter. I personally feel that I rarely see a number separated by spaces. It does allow the dot for currency formatting. The dot is however frequently used in systems (including many spreadsheet programs, etc). Wikipedia has a short note (German) on some of the benefits and issues with using a dot as a delimiter.
There's a separate technical issue with the space-delimiter -- it frequently causes line breaks in long numbers, which should not happen either. There are two alternatives to fix this issue:
While I still prefer the dot as a thousands delimiter over a space, I do see a valid point in sticking with the space-delimiter. In this case it might make sense to switch to the narrow no-break space character though to prevent line breaks.
The breaking issue is real. Moreover, narrow spaces are not necessarily any narrower in the actual rendering. The dot is, in fact, often a better-looking choice. Ideally, this would be configurable.
As far as I can tell, the options regarding the thousands-delimiter in the German language implementation are as follows:
In general, Option 1.b is probably better than the current implementation of 1.a, due to line-breaks. Personally I still prefer 1.c. Option 3 sounds good, but is probably unrealistic. Especially 3.b sounds wholly unattainable, since there are likely conflicting standards. So you'd need 3b + 3a. I'm skeptical...
Is there a possibility to overwrite the default delimitier? I dont want to modifiy the language file, because if I update the library via bower the modifications are gone.
@crebuh You could override the delimeter with jQuery $.extend
or any other extend method.
numeral.language('de', $.extend(numeralDE, { delimiters: {thousands: '.', decimal: ','} }));
Couldn't we just add a de-alt.js
with dot configuration. This would save many german developers lots of time. As both variants are standardized, both options should be available.
Anyone that may be still struggling with it, I managed to make it work as follows:
import numeral from 'numeral';
require('numeral/locales/de');
numeral.locale('de');
numeral.localeData('de').delimiters.thousands = '.';
export const formatNumber = (number) => (
numeral(number).format('0,0.000')
);
And then I call my function like
formatNumber(12302) // 12.302
formatNumber(12302,34) // 12.302,340
Hi,
I am considering using Numeral.js and it's language extensions in my project. I noticed that the German number representation is incorrect.
For example: A number "12345678.91" when formatted using DE language pack, is incorrectly formatted as "12 345 678,91", whereas it should ideally be "12.345.678,91" per http://userguide.icu-project.org/formatparse
Am i missing something here? Here's my sample code - require(['lib/numeral/min/numeral.min/numeral', 'lib/numeral/languages/de' ], function (numeral, language) { numeral.language('de', language); var number = numeral(12345678.91); console.log("DE:" + number.format('0,0.00')); });
Thanks for creating Numeral.js and it's associated language packs!