Use browser locale to get the correct currency

2,411 views
Skip to first unread message

Maryam Booshehrian

unread,
May 15, 2017, 2:43:12 PM5/15/17
to vega-js
Hi,

I have been looking at vega (and d3) source code and found out that if we specify "$" in the axis format, it should apply the correct currency from the list it has to the tick values. However, when I change the default browser language to France French, I still see "$" instead of "€" (euro sign). I am wondering if anybody has experience with currency in vega. How can I force vega to get the browser language to proprely show currency signs?

Thanks!

Robin Millette

unread,
Jun 10, 2017, 7:02:15 PM6/10/17
to vega-js
Numbers support toLocaleString(...):
https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Number/toLocaleString#Using_options

From that page:

var number = 123456.789;

// request a currency format
console.log(number.toLocaleString('de-DE', { style: 'currency', currency: 'EUR' }));
// → 123.456,79 €

console
.log(number.toLocaleString('fr-CA', { style: 'currency', currency: 'CAD' }));
// → 123.456,79 CA$



Reply all
Reply to author
Forward
0 new messages