I've been looking into locale aware number formatting for javascript and found that Number.toLocaleString
and by extension Intl.NumberFormat appear to be good solutions for this problem.
In particular I'd prefer building on top of already implemented abstractions for locale specific formatting rather than reinventing the wheel and coming up with one more solution to an already solved problem.
So I've called Number.toLocaleString
on some different javascript environments and found that currency formatting seems to have changed:
(5).toLocaleString('fr-CH', {currency: 'CHF', style: 'currency'});
// Node v10.15.1: 'CHF 5.00'
// Node v12.1.0: '5.00 CHF'
// Firefox 66.0.2: '5.00 CHF'
// Chrome 73.0.…: '5.00 CHF'
// Safari 12.0.3: '5.00 CHF'
// IE 11: '5.00 fr.'
- IE 11 is different than the rest, but it doesn't surprise me given its age.
- What surprises me is that the formatting for
CHF
infr-CH
seems to have changed between node versions10
and12
. - For comparison I had a look at the glibc LC_MONETARY settings for fr_CH and found that it seems to place the
CHF
before the amount at least about 1997. This makes it particularly confusing that the position ofCHF
seems to be different for most current browsers.
I would like to know and understand:
- Why are the positions of the
CHF
different in these cases?- I know that this can depend on the available system locales or the browser. But the change between node versions seems to indicate a more recent and voluntary change to me.
- Is there a correct way to place the
CHF
or are both choices acceptable for CH, or more specificallyfr-CH
?- For this it would be beautiful to have an actual source like a paper or research database rather than hearsay or anecdotes.
Update (2019-05-16):
In reaction to my partial answer I'd like to specify:
- The formatting decision for
fr_CH
is given ascurrencyFormat{"#,##0.00 ¤ ;-#,##0.00 ¤"}
in commit 3bfe134 but I'm still missing a source for the decision and would love to know about it.