Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

German number representation is incorrect #139

Open
asagrawal opened this issue Feb 3, 2014 · 10 comments
Open

German number representation is incorrect #139

asagrawal opened this issue Feb 3, 2014 · 10 comments

Comments

@asagrawal
Copy link

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!

@asagrawal
Copy link
Author

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?

@morioust
Copy link

Yes, the thousands delimiter should be a '.', not a ' '.

morioust pushed a commit to morioust/Numeral-js that referenced this issue Jul 15, 2014
@piefel
Copy link
Contributor

piefel commented Jul 16, 2014

Actually, no, the space is not incorrect. You can use both in German typograhpy.

@morioust
Copy link

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.

@piefel
Copy link
Contributor

piefel commented Jul 18, 2014

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.

@morioust
Copy link

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 Change thousands delimiter from ' ' to '.' in German (#139) #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...

@crebuh
Copy link

crebuh commented Feb 20, 2015

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.

@akkie
Copy link

akkie commented Mar 19, 2015

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

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

@buffcode
Copy link

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.

@jprivillaso
Copy link

jprivillaso commented Aug 22, 2019

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants