New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Formatting currencies #238

Closed
ragulka opened this Issue Apr 23, 2014 · 11 comments

Comments

Projects
None yet
4 participants
@ragulka

ragulka commented Apr 23, 2014

PR #351

It seems that the CLDR (new) version of Globalize does not yet support formatting currencies? Can we expect this to be featured in 1.0.0?


Editted by @rxaviers

Needs:

  • #335 Plural generator

API Examples

Globalize( "de" ).formatCurrency( 1337, "EUR" );   
// 1337,00 €
Globalize( "de" ).formatCurrency( 53.07, "EUR", { style: "code" } );  
// 53,07 EUR
Globalize( "de" ).formatCurrency( 53.07, "EUR", { style: "name" } );  
// 53,07 Euro

Globalize( "en" ).formatCurrency( 53.07, "EUR" );  
// €53.07
Globalize( "en" ).formatCurrency( 53.07, "EUR", { style: "code" } );  
// 53.07 EUR
Globalize( "en" ).formatCurrency( 53.07, "EUR", { style: "name" } );  
// 53.07 euros

Globalize( "zh-Latn" ).formatCurrency( 1337, "EUR" );   
// € 1337,00
Globalize( "zh-Latn" ).formatCurrency( 53.07, "EUR", { style: "code" } );  
// 53,07EUR
Globalize( "zh-Latn" ).formatCurrency( 53.07, "EUR", { style: "name" } );  
// 53,07欧元

Adds currency as option

CLDR

Open questions:

@rxaviers

This comment has been minimized.

Member

rxaviers commented Apr 23, 2014

Absolutely.

@AltiusRupert

This comment has been minimized.

AltiusRupert commented Jun 9, 2014

Great news ! What's the progress on this ? Will we come back to something like g.format(123.45, 'c(EUR)') ?

@rxaviers

This comment has been minimized.

Member

rxaviers commented Jun 9, 2014

This ticked will be updated with the progress of the implementation... The new format hasn't been discussed yet. But, it's going to be in the lines of either or all:

Globalize.formatCurrency({EUR: 123.45});
Globalize.formatCurrency({currency: "EUR", value: 123.45});
Globalize.formatCurrency(123.45, {currency: "EUR"});
@AltiusRupert

This comment has been minimized.

AltiusRupert commented Jun 9, 2014

Hi Rafael,
Is it necessary to have a specific formatCurrency method ?
Would it not be easier to group currency-formatting and number-formatting options in the same formatNumber method ?

In your example below, how do I specify thousands-separators and decimal-point of the amount in the currency ?

Le 9 juin 2014 à 18:41, Rafael Xavier de Souza notifications@github.com a écrit :

This ticked will be updated with the progress of the implementation... The new format hasn't been discussed yet. But, it's going to be in the lines of either or all:

Globalize.formatCurrency({EUR: 123.45});
Globalize.formatCurrency({currency: "EUR", value: 123.45});
Globalize.formatCurrency(123.45, {currency: "EUR"});

Reply to this email directly or view it on GitHub.

@rxaviers

This comment has been minimized.

Member

rxaviers commented Jun 9, 2014

Hi Rupert,

Ungrouping the different format() methods has been decided in this discussion due to simpler code and use clarity. Note, error handling can be better predicted as well.

The current plan is that a currency module (globalize/currency.js) will hold the extra code for currency formatting and parsing. Therefore, the initial idea is to follow the same pattern of not overloading existing methods (in this case formatNumber()). But, to create a new one (formatCurrency()). Let's see what the code complexity will be though...

In your example below, how do I specify thousands-separators and decimal-point of the amount in the currency ?

It inherits the same options/attributes from number formatting that allows you to do that. ;)

@jzaefferer

This comment has been minimized.

Contributor

jzaefferer commented Jun 9, 2014

I was just wondering the same. Adding the currency option to formatNumber seems pretty reasonable from a usage point of view.

The only option that looks like it would conflict is style, since it wouldn't make sense to format a currency as a percentage. Extending style to accept currency as a valid value would leave the problem of how to specify the currency itself. style: "EUR" seems like a bad idea, too.

Regarding the discussion Rafael links to, that didn't mention formatCurrency.

@rxaviers

This comment has been minimized.

Member

rxaviers commented Jun 9, 2014

Regarding the discussion Rafael links to, that didn't mention formatCurrency.

Well, I didn't say it does. The discussion mentions "ungrouping the different format() methods", or in other words, not overloading the same method.

@jzaefferer

This comment has been minimized.

Contributor

jzaefferer commented Jun 9, 2014

Numbers and dates deserve their own methods, which is what we discussed. Currencies are also numbers, so stuffing them into formatNumber is pretty reasonable.

Would be good to get some implementation data - is the currency module significant overhead to justify not burdening the number module with it? That is, if someone doesn't need currencies, does it matter that he also has to load the currency module? If the size difference is negligible and we can figure out the options, extending formatNumber seems good to me.

@AltiusRupert

This comment has been minimized.

AltiusRupert commented Jun 9, 2014

Jörn,
You could still have two modules loading features to the same formatNumber method : only the values of options will differ, as well as extra submethods.

Le 9 juin 2014 à 20:27, Jörn Zaefferer notifications@github.com a écrit :

Numbers and dates deserve their own methods, which is what we discussed. Currencies are also numbers, so stuffing them into formatNumber is pretty reasonable.

Would be good to get some implementation data - is the currency module significant overhead to justify not burdening the number module with it? That is, if someone doesn't need currencies, does it matter that he also has to load the currency module? If the size difference is negligible and we can figure out the options, extending formatNumber seems good to me.


Reply to this email directly or view it on GitHub.

@jzaefferer

This comment has been minimized.

Contributor

jzaefferer commented Jun 9, 2014

Yeah, but then you have to require a module that you don't actually use, just like jQuery plugins. Something I'd like to avoid.

@rxaviers rxaviers added this to the 1.0.0 milestone Sep 1, 2014

@ragulka

This comment has been minimized.

ragulka commented Sep 5, 2014

Hopefully this will make it to 1.0.0 :)

This was referenced Sep 30, 2014

rxaviers added a commit that referenced this issue Nov 28, 2014

@rxaviers rxaviers referenced this issue Nov 28, 2014

Closed

Implement currency formatting #351

3 of 3 tasks complete

rxaviers added a commit that referenced this issue Dec 1, 2014

Currency: Use supplemental currency data
The number of decimal places and the rounding for each currency is not
locale-specific. Those values are overridden by Supplemental Currency
Data.

Ref #238

rxaviers added a commit that referenced this issue Dec 1, 2014

rxaviers added a commit that referenced this issue Dec 1, 2014

Doc: Add currency formatting
- Add `.currencyFormatter( currency [, options] )`;
- Add `.formatCurrency( value, currency [, options] )`;

Ref #238

rxaviers added a commit that referenced this issue Dec 2, 2014

Currency: Use supplemental currency data
The number of decimal places and the rounding for each currency is not
locale-specific. Those values are overridden by Supplemental Currency
Data.

Ref #238

rxaviers added a commit that referenced this issue Dec 2, 2014

rxaviers added a commit that referenced this issue Dec 2, 2014

Doc: Add currency formatting
- Add `.currencyFormatter( currency [, options] )`;
- Add `.formatCurrency( value, currency [, options] )`;

Ref #238

rxaviers added a commit that referenced this issue Dec 2, 2014

Doc: Add currency formatting
- Add `.currencyFormatter( currency [, options] )`;
- Add `.formatCurrency( value, currency [, options] )`;

Ref #238
Ref #351

rxaviers added a commit that referenced this issue Dec 2, 2014

rxaviers added a commit that referenced this issue Dec 2, 2014

Currency: Use supplemental currency data
The number of decimal places and the rounding for each currency is not
locale-specific. Those values are overridden by Supplemental Currency
Data.

Ref #238
Ref #351

rxaviers added a commit that referenced this issue Dec 2, 2014

rxaviers added a commit that referenced this issue Dec 2, 2014

Doc: Add currency formatting
- Add `.currencyFormatter( currency [, options] )`;
- Add `.formatCurrency( value, currency [, options] )`;

Ref #238
Ref #351

rxaviers added a commit that referenced this issue Dec 10, 2014

rxaviers added a commit that referenced this issue Dec 10, 2014

Currency: Use supplemental currency data
The number of decimal places and the rounding for each currency is not
locale-specific. Those values are overridden by Supplemental Currency
Data.

Ref #238
Ref #351

rxaviers added a commit that referenced this issue Dec 10, 2014

rxaviers added a commit that referenced this issue Dec 10, 2014

Doc: Add currency formatting
- Add `.currencyFormatter( currency [, options] )`;
- Add `.formatCurrency( value, currency [, options] )`;

Fixes #238
Closes #351

rxaviers added a commit that referenced this issue Dec 10, 2014

Currency: Use supplemental currency data
The number of decimal places and the rounding for each currency is not
locale-specific. Those values are overridden by Supplemental Currency
Data.

Ref #238
Ref #351

rxaviers added a commit that referenced this issue Dec 10, 2014

rxaviers added a commit that referenced this issue Dec 10, 2014

Doc: Add currency formatting
- Add `.currencyFormatter( currency [, options] )`;
- Add `.formatCurrency( value, currency [, options] )`;

Fixes #238
Closes #351

@rxaviers rxaviers closed this in bb3f7b3 Dec 10, 2014

@rxaviers rxaviers referenced this issue Dec 10, 2014

Open

Currency parsing #364

1 of 1 task complete

rxaviers added a commit that referenced this issue Dec 11, 2014

rxaviers added a commit to rxaviers/globalize that referenced this issue Feb 15, 2015

rxaviers added a commit that referenced this issue Feb 15, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment