The example in the docs:
var number = 123456.789;
// request a currency format
console.log(new Intl.NumberFormat('de-DE', { style: 'currency', currency: 'EUR' }).format(number));
// → 123.456,79 €
My output in Node 10:
> new Intl.NumberFormat('de-DE', { style: 'currency', currency: 'EUR' }).format(123456.789)
'€ 123,456.79'
Euro symbol on the right in the docs. On the left when I actually run the code. Do I have to set a locale or something? I'm in the US. But I'm actually asking for de-DE
format, seems like that should override my locale. Running the exact code from the example made no difference.
Very likely you Node does not have full locale support for Intl, only English (small-icu
)
See https://nodejs.org/api/intl.html#intl_detecting_internationalization_support
Try the "To check for support for a non-English locale" part.
Solution (if you have small-icu
, the most likely case)
You can (of course) recompile (as the page linked above recommends)
But you can use a shortcut, it might work and save you some time
process.versions.icu
(in my case is '62.1'
, for node v10.15.3
)<version>
/icu4c-<version>
-src.tgz.icu/source/data/in/icudt62l.dat
. But the location might be different in other ICU versions (although I doubt, it is not impossible :-)NODE_ICU_DATA
to point to the date file.
Either export NODE_ICU_DATA=<icu_data_path>/icudt62l.dat
(define the variable) or env NODE_ICU_DATA=<icu_data_path>/icudt62l.dat node
(define + run node)It is pretty lame that Node does not provide versions with full ICU support ready to download.
Or at least archived ICU data files matching the Node releases, so that we don't have to go through all this digging.