Node: wrong localisation for currency in toLocaleString

Created on 7 Sep 2016  Â·  7Comments  Â·  Source: nodejs/node

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

i18n-api

Most helpful comment

@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.

All 7 comments

/cc @nodejs/intl

  • 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

@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.

Thnx, has to be considered for server side rendering!

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.

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

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

Related issues

addaleax picture addaleax  Â·  3Comments

dfahlander picture dfahlander  Â·  3Comments

danialkhansari picture danialkhansari  Â·  3Comments

srl295 picture srl295  Â·  3Comments

Brekmister picture Brekmister  Â·  3Comments