Skip to content
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

Format using ISO Code #46

Closed
sliekens opened this issue Aug 26, 2016 · 4 comments
Closed

Format using ISO Code #46

sliekens opened this issue Aug 26, 2016 · 4 comments
Assignees
Labels

Comments

@sliekens
Copy link

sliekens commented Aug 26, 2016

At the moment, ToString formats money using its currency symbol, but symbols can be ambiguous. Please add a method that formats money using its unambiguous currency code instead.

See wikipedia's section on formatting rules: https://en.wikipedia.org/wiki/ISO_4217#Position_of_ISO_4217_code_in_amounts

In my opinion, formatting using the ISO code should have been the default result of calling Money.ToString() and formatting using the currency symbol should have been the result of calling Money.ToString("C")

@RemyDuijkeren RemyDuijkeren added this to the v0.7.0 milestone Sep 9, 2016
@RemyDuijkeren RemyDuijkeren self-assigned this Sep 9, 2016
@RemyDuijkeren
Copy link
Owner

RemyDuijkeren commented Sep 10, 2016

I agree symbols (signs) can be ambiguous, but this is what people expect when looking at money. The symbol primarly defines that a value represents money. That money later is formalized by ISO with codes and numbers, doesn't take this away.

The ISO code is only used in edge cases, where it must be totally clear which currency is used (legal, exchange, etc). Also NodaMoney can be used by non-ISO currencies like bitcoin or your own imaginary currency like some game currency or facebook coins. So I don't think Money.ToString() should give the ISO code, but instead should give the symbol.

Also using Decimal.ToString("C") the number is formatted with the currency symbol, which means the symbol is the default what people expect.

Of course NodaMoney should support formatting with the ISO code, which is on the planning, but Format Strings can be a complex job :-(. There is a way to do it by using string.Format("{0} {1}", money.Code, money.Amount), so that the reason I postponed it ;-).

I was thinking about adding a couple of Standard Money Format Strings:

Format specifier Description Examples
C currency symbol pattern (default) € 23.002,43 , € 23,002.43, 23,002.43 €
I currency code pattern EUR 23.002,43 , EUR 23,002.43 , 23.002,43 EUR
O Round-trip money pattern EUR 23002,43
N Number pattern 23.002,43 , 23,002.43
F currency english name pattern 23.002,43 dollar
f currency native name pattern 23.002,43 dólar

What do you think?

@carlosschults
Copy link
Contributor

Hey, all. I'd like to start contributing to NodaMoney. Can I have a try at implementing one of the Format Strings?

@RemyDuijkeren
Copy link
Owner

Yes, all help is welcome. Send it as a pull request. Thanks!

@RemyDuijkeren
Copy link
Owner

Format C, I and F are working, see https://github.com/remyvd/NodaMoney/blob/master/tests/NodaMoney.Tests/MoneyFormattableSpec.cs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants