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

More elaborate way of money conversion #5

Open
jodastephen opened this issue Dec 10, 2012 · 2 comments
Open

More elaborate way of money conversion #5

jodastephen opened this issue Dec 10, 2012 · 2 comments
Labels

Comments

@jodastephen
Copy link
Member

From https://sourceforge.net/u/tompasik/profile/
https://sourceforge.net/p/joda-money/feature-requests/2/

I've been developing such a "money" module myself but I was nowhere close to the joda-money solution when I found out about it. Thanks and congrats for this very nice library.

Now, what would be nice to see in the library (in my opinion) is a more elaborate way to convert money instances between different currency units.

I think I could provide an initial version of such a utility class. I think it would supplement the money functionality that the library already provides.

The thing I propose is an object having the following functionality - I present it here as an interface, I have it implemented as a class.

class ExchangeRate {
// Converts the given money to the monetary amount in this rates other currency.
Money exchange(Money toExchange);

// Combines to exchange rates together that have a common currency units
ExchangeRate combine(ExchangeRate other);
}

An instance of exchange rate is something that represents the following "equasion": 1 unit of target currency = n units of source currency.
An example would be:
1 EUR = 1.3 USD

A user can pass either an amount in EUR or USD to get an equivalent Money instance in the other currency.

The combine operation would allow the user to get a cross exchange rate. If one has the following exchange rates:
1 EUR = 1.3 USD
1 GBP = 1.55 USD
than a combination of the first and second would result in the following rate:
1 EUR = 0.838710 GBP.

The convertedTo method on Money object could internally construct an instance of ExchangeRate and use the conversion logic.

I don't have the fancy ;-) from String parsing methods nor any special formatters for it but I think it would be a good start.

Tell me what you think about it.

@jodastephen
Copy link
Member Author

I think that some kind of exchange rate interface probably makes sense in an API like this. It will need to be simple and unobtrusive, as different domains have very different demands on what they need from such a conversion. I suspect that the combining of rates is probably more complex than is needed, and that should be up to the application for example.

If you want to propose something, you could fork GitHub and try something out....

@jodastephen
Copy link
Member Author

Please review the exchangerate branch
https://github.com/JodaOrg/joda-money/tree/exchangerate

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

No branches or pull requests

1 participant