MinorIntegralAmount and rounding

7 views
Skip to first unread message

Peter McEvoy

unread,
Dec 11, 2012, 7:00:00 AM12/11/12
to nmo...@googlegroups.com
Hi there,
I'm not sure that I agree with the following test:

Assert.That(new Money(12.378m, Currency.Eur).MinorIntegralAmount, Is.EqualTo(1237L));

I would expect the following to pass instead:

Assert.That(new Money(12.378m, Currency.Eur).MinorIntegralAmount, Is.EqualTo(1238L));
Assert.That(new Money(12.373m, Currency.Eur).MinorIntegralAmount, Is.EqualTo(1237L));

(I don't know what the rounding rules are when it's 12.375)

The reason for this is that 12.378 when .ToString'd is output as 12.38 and thus it's surprising that .MinorIntegralAmount outputs as 1237.

Many online payment providers insist that you send the payment amount to them in the minor units of the currency (to avoid issues with decimal points), and thus .MinorIntegralAmount is a great property for that.  However this slight rounding issue leads to surprises in what we display on our site and what is displayed on the payment provider site.

If this is not what this property is intended for, then could you suggest an alternate approach?

dgon

unread,
Dec 11, 2012, 12:29:11 PM12/11/12
to nmo...@googlegroups.com
Hi Peter,

MinorIntegralAmount is not meant to perform any rounding, that is what .Round() methods are for. MinorIntegralAmount only takes the amount up to the minor significant digit, discarding the rest.

.ToString() performs some rounding internally, hence the confusion.
Reply all
Reply to author
Forward
0 new messages