MinorIntegralAmount and rounding

19 views
Skip to first unread message

Peter McEvoy

unread,
Dec 11, 2012, 7:31:29 AM12/11/12
to nmo...@googlegroups.com
Further to my previous (waiting for it to be approved so cannot reply directly to it), I added the following extension to my code.  Perhaps something similar could be rolled into the base library?

public static long RoundedMinorIntegralAmount(this Money money)
{
var rounded = money.Round();
return rounded.MinorIntegralAmount;
}

dgon

unread,
Dec 11, 2012, 12:38:28 PM12/11/12
to nmo...@googlegroups.com
Adding and extension method for your particular case would be the preferred way of extending the library and you used the methods provided perfectly.

At first glance, I would be hesitant to add such an specific method -and all its overrides, as .Round() has some complex behavior- to the code base, but if you are interested, I am not against accepting a patch with unit tests showcasing your desired behavior.

Regards

Peter McEvoy

unread,
Dec 12, 2012, 4:10:53 AM12/12/12
to nmo...@googlegroups.com
I completely agree that adding such a method to an already established API is a delicate thing.

I guess what caught me was not being aware that .MinorIntegralAmount would not round (I did read "truncate", but was not aware of the significance) - perhaps I could suggest that the "For example" in the remarks section include more than two decimal digits?  EG 2.357 -> 235

Anyway, this is by no means a criticism and your library has saved me a veritable metric tonne of hassle!

dgon

unread,
Dec 12, 2012, 4:19:38 AM12/12/12
to nmo...@googlegroups.com
No problem Peter, I did not take it as criticism at all, but as feedback and, man, do I like that.
As a matter of fact, it was so valuable that your comment gave me an idea of another point of extension for Money.

I will be adding a more clear example of the significance of both methods, both in documentation and in tests.
Actually, some people will be glad to know that the next release of NMoneys will come with generated API documentation, including this case ;-).

Glad to hear that the library is useful.
Cheers
Reply all
Reply to author
Forward
0 new messages