Numeral-js: German number representation is incorrect

Created on 3 Feb 2014  路  10Comments  路  Source: adamwdraper/Numeral-js

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!

Most helpful comment

@crebuh You could override the delimeter with jQuery $.extend or any other extend method.

numeral.language('de', $.extend(numeralDE, { delimiters: {thousands: '.', decimal: ','} }));

All 10 comments

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:

  1. Use the _narrow no-break space_ character ( )
  2. Specify _white-space: nowrap_ in CSS

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:

  1. Decide on language-level: Pick a single formatting option
    a) No change: keep current white-space separator
    b) Use NNBSP
    c) Use dot (.) - merge #192
    => I'd chose the dot due to subjective perception of frequency of usage. The closest to the standard is probably NNBSP. Probably none of these options will make everyone happy.
  2. Decide on project-level: Everyone overrides the German language set with project-specific custom language, if desired.
  3. Decide on library-level:
    a) Make Numeral.js agnostic and provide some sort of configurability.
    b) Make Numeral.js incredibly complex and understand the intrinsic rules of all languages (e.g. in this case, use a narrow space for all numbers, use dot for currency-formatting).

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
Was this page helpful?
0 / 5 - 0 ratings

Related issues

meafmira picture meafmira  路  8Comments

ragulka picture ragulka  路  6Comments

tony-kerz picture tony-kerz  路  6Comments

anselms picture anselms  路  4Comments

jonathanbergson picture jonathanbergson  路  6Comments