1

I am using globalize.js for currency formatting for different countries. Using this link I am able to achieve for USD, but I need USD and JPY or for any country. I followed all the tutorials mentioned in the globalize. Please anyone help me to solve this issue.

Rory McCrossan
  • 331,213
  • 40
  • 305
  • 339
user3446501
  • 31
  • 1
  • 6

1 Answers1

1

You need to load the appropriate portions of CLDR, specifically main/currencies (e.g., https://github.com/unicode-cldr/cldr-numbers-modern/blob/master/main/en/currencies.json).

Follow an example using npm / node:

npm install globalize cldr-data
node

-

var Globalize = require('globalize');
Globalize.load(require('cldr-data').entireSupplemental());
Globalize.load(require('cldr-data').entireMainFor('en', 'de', 'ja'));

Globalize('en').formatCurrency(9.99, 'EUR')
// > '€9.99'

Globalize('de').formatCurrency(9.99, 'EUR')
// > '9,99 €'

Globalize('en').formatCurrency(10, 'JPY')
// > '¥10'

Globalize('ja').formatCurrency(10, 'JPY')
// > '¥10'

For more information about (or alternative ways of) how to get CLDR data or how to load CLDR data into Globalize, see https://github.com/jquery/globalize/blob/master/doc/cldr.md.

Rafael Xavier
  • 2,840
  • 27
  • 34
  • Sorry, could you expand your answer on what to do next, after CLDR is in place? Thanks. – sompylasar Apr 22 '16 at 21:20
  • I tried for JPY with jp Currency.json format inside the Globalize.load. But its not working. Whatever tutorial followed in this [Link](https://raw.githubusercontent.com/jquery/globalize/master/examples/plain-javascript/index.html) i tried with the same. My main requirements is based on country locale i need to change Currency format. Please help me to solve this issue. – user3446501 Apr 25 '16 at 07:21
  • My main issue is i need to change currency format based on locale. Please help me to sole this issue – user3446501 Apr 25 '16 at 07:49
  • I've added an example. Note the locale for Japanese is `ja` (not `jp`). Please, just let me know if that helps or if you have further questions. – Rafael Xavier May 30 '16 at 09:28