Skip to main content

[JSR-354] Re: Mathematical Operations on MonetaryAmount

  • From: Werner Keil <werner.keil@...>
  • To: jcurrency_mail@...
  • Subject: [JSR-354] Re: Mathematical Operations on MonetaryAmount
  • Date: Sat, 13 Jul 2013 16:57:55 +0200

GBP 5 * USD 5 would currently throw a CurrencyMismatchException. And so did
something like
GBP 5 + EUR 5, etc.

Explicit conversion of one currency before you perform those operations is
required and unless very specific implementations doing that under the hood
were written (unlikely that makes sense for RI, at least there are always
different conversion rates and fees for such conversions)

EUR 5 + 5 can be seen more or less like a convenience method. Take some of
the "Diamond" improvements to Java 7.
Previously you had to declare a generic type twice, now Java will recognize
and use the correct type for you.
Given the most common cases will use the same currency and calculations
with different currencies at least by the RI would normally throw an
exception, I would not say the MonetaryAmount + MonetaryAmount version
should be dropped, but the "convenience" or "diamond like" version that
assumes the only valid currency seems quite appropriate, too.

Werner

On Sat, Jul 13, 2013 at 4:34 PM, Chris Pheby <chris@...> wrote:

>  My question was:****
>
> ** **
>
> GBP5 *  5  = GBP 25 is clear enough****
>
> ** **
>
> But not sure about****
>
> ** **
>
> GBP 5 * GBP 5  ****
>
> or even ****
>
> GBP 5 * USD 5****
>
> ** **
>
> In what situation would you perform these multiplications?****
>
> ** **
>
> Similarly****
>
> ** **
>
> EUR 5 + EUR 5 seems clear****
>
> But****
>
> EUR5 + 5 is less clear****
>
> ** **
>
> Regards Chris****
>
> ** **
>
> *From:* Werner Keil [mailto:werner.keil@...]
> *Sent:* 13 July 2013 22:29
> *To:* jcurrency_mail@...
> *Subject:* [JSR-354] Re: Mathematical Operations on MonetaryAmount****
>
> ** **
>
> I remember the latter method was to add a numeric amount of the same
> currency. We do have a restriction or guidance, that the currencies of both
> arguments should be the same, otherwise one would never know, which
> exchange rate to explicitely use and where to take it from****
>
> ** **
>
> So I'd say it makes sense in both cases. For multiplication it certainly
> does even more, are we missing a numeric only argument there?
>
> Regards,****
>
> Werner****
>
> On Sat, Jul 13, 2013 at 4:15 PM, Chris Pheby <chris@...> wrote:**
> **
>
> On MonetaryAmount, most of the mathematical operations are overloaded for
> both MonetaryAmount and Number as parameters. I am not sure this should be
> the case.****
>
>  ****
>
> For example, add and subtract:****
>
>  ****
>
>     *public* Money add(MonetaryAmount amount);****
>
>     *public* Money add(Number amount);****
>
>  ****
>
> Adding two MonetaryAccounts makes perfect sense, but adding a number to a
> monetary amt – less clear. Why not just convert the number to a
> MonetaryAmount explicitly.****
>
>  ****
>
> For the multiply, divide… and remainder methods, the opposite may be true.
> In this case, it is unclear what the meaning of using a MonetaryAmount as
> an operand is.****
>
>  ****
>
> Regards Chris****
>
>  ****
>
>  ****
>
>  ****
>
> **
>

Attachment: image001.gif
Description: GIF image



[JSR-354] Mathematical Operations on MonetaryAmount

Chris Pheby 07/13/2013

[JSR-354] Re: Mathematical Operations on MonetaryAmount

Werner Keil 07/13/2013

[JSR-354] Re: Mathematical Operations on MonetaryAmount

Chris Pheby 07/13/2013

[JSR-354] Re: Mathematical Operations on MonetaryAmount

Werner Keil 07/13/2013

[JSR-354] Re: Mathematical Operations on MonetaryAmount

tom.huesler@... 07/13/2013

[JSR-354] Re: Mathematical Operations on MonetaryAmount

Werner Keil 07/14/2013

[JSR-354] Re: Mathematical Operations on MonetaryAmount

Chris Pheby 07/14/2013

[JSR-354] Re: Mathematical Operations on MonetaryAmount

Stephen Colebourne 07/14/2013

[JSR-354] Re: Mathematical Operations on MonetaryAmount

Werner Keil 07/14/2013

[JSR-354] Re: Mathematical Operations on MonetaryAmount

Werner Keil 07/14/2013

[JSR-354] Re: Mathematical Operations on MonetaryAmount

Werner Keil 07/16/2013

[JSR-354] Re: Mathematical Operations on MonetaryAmount

Sascha Freitag 07/28/2013

[JSR-354] Re: Mathematical Operations on MonetaryAmount

Werner Keil 07/28/2013

[JSR-354] Re: Mathematical Operations on MonetaryAmount

Anatole Tresch 07/14/2013
 
 
Close
loading
Please Confirm
Close