globalizejs / globalize

A JavaScript library for internationalization and localization that leverages the official Unicode CLDR JSON data
https://globalizejs.com
MIT License
4.8k stars 603 forks source link

Globalize - Currency Formatting and Parsing #840

Closed pkasib closed 6 years ago

pkasib commented 6 years ago

Hi,

We are trying to migrate from Globalize 0.x to 1.X, and are facing certain issues in the migration wrt currency formatting.

1) Previously we could format a currency by the current locale, and provide our own symbol (ex : $) as follows: var xtml = jQuery.extend(true, {}, Globalize.culture()); xtml.numberFormat.currency.symbol = currencySymbol; obj.value = Globalize.format(Globalize.parseFloat(obj.value), "C", xtml);

It would seem this behavior no longer exists. Now it would seem we have to specify the currency type (ex: USD). Is there any way in which to extract the currency code from the currency symbol?

2) It would seem there is no way to format a currency without a symbol, as I viewed on some previous threads. Whereas previously it was possible:

xtml.numberFormat.currency.symbol = ''; obj.value = Globalize.format(tmpFLoat, "C", xtml);

Is there some way to do this now, without having to resort to reg ex checks and programatically stripping out currencies?

3) We also need to parse a number from a currency.

Example : Parse 12345 from $12,345.

The current parse number method breaks when it encounters currency symbols, and I see there is a method called - parsecurrency, but it always returns undefined.

rxaviers commented 6 years ago

Questions are better suited for stackoverflow (instructions). Issues should be used to report bugs or discuss new features. Please, could you post your question there (you can even link it in here later)? Thanks