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

wrong localisation for currency in toLocaleString #8433

Closed
odotom opened this issue Sep 7, 2016 · 7 comments
Closed

wrong localisation for currency in toLocaleString #8433

odotom opened this issue Sep 7, 2016 · 7 comments
Labels
i18n-api Issues and PRs related to the i18n implementation.

Comments

@odotom
Copy link

odotom commented Sep 7, 2016

Example:
const amount = 12345.67
const options = {style: 'currency', currency: 'EUR'}
amount.toLocaleString('de-DE', options)
-> '€ 12,345.67'

should be
'12.345,67 €'

(Be aware that the grouping separator for DE is also wrong!)
This happens only when using currency localisation
Reference: Chrome v53 performs correctly

@mscdex mscdex added the i18n-api Issues and PRs related to the i18n implementation. label Sep 7, 2016
@mscdex
Copy link
Contributor

mscdex commented Sep 7, 2016

/cc @nodejs/intl

@odotom
Copy link
Author

odotom commented Sep 7, 2016

  • Version: v6.5.0
  • Platform: Darwin macpro_to 15.6.0 Darwin Kernel Version 15.6.0: Mon Aug 29 20:21:34 PDT 2016; root:xnu-3248.60.11~1/RELEASE_X86_64 x86_64

@srl295
Copy link
Member

srl295 commented Sep 7, 2016

@odotom the cause is a lack of locale data. see https://github.com/nodejs/node/wiki/Intl

With the right data I get

$ node -v
6.5.0
$ npm i full-icu
……  node --icu-data-dir=node_modules/full-icu ………
$ node --icu-data-dir=node_modules/full-icu
> const amount = 12345.67
> const options = {style: 'currency', currency: 'EUR'}
> amount.toLocaleString('de-DE', options)
'12.345,67 €'

Do let me know if you have issues or questions about the data, but as an issue I'm closing it.

@srl295 srl295 closed this as completed Sep 7, 2016
@odotom
Copy link
Author

odotom commented Sep 7, 2016

Thnx, has to be considered for server side rendering!

@jasnell
Copy link
Member

jasnell commented Sep 7, 2016

Node.js, by default, only includes the data files for the English locale. It is possible to download the full data set using the full-icu module.

@srl295
Copy link
Member

srl295 commented Sep 7, 2016

@odotom updated my reply above w/ more about using full-icu

@Fuzzyma
Copy link

Fuzzyma commented Dec 11, 2017

@srl295 This is still broken. The options minimumFractionDigits and maximumFractionDigits are not working correctly.

Consider the numbers 1234.00001 and 1234.123456:

// outputs '1,234.00' instead of '1,234.000'
// the defaul of maximum is max(minimumFractionDigits, 3) so it should ouput 3 zeros
1234.00001.toLocaleString('en-GB', {useGrouping: true, minimumFractionDigits: 2})

// correctly outputs '1,234.123'
1234.123456.toLocaleString('en-GB', {useGrouping: true, minimumFractionDigits: 2})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
i18n-api Issues and PRs related to the i18n implementation.
Projects
None yet
Development

No branches or pull requests

5 participants