Skip to content

More elaborate way of money conversion  #5

@jodastephen

Description

@jodastephen

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No fields configured for Feature.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions