Skip to content

Commit 5700d5e

Browse files
committed
FINERACT-2326: Fix rounding of BigDecimal when added to Money object
1 parent 01ca515 commit 5700d5e

File tree

1 file changed

+4
-8
lines changed
  • fineract-core/src/main/java/org/apache/fineract/organisation/monetary/domain

1 file changed

+4
-8
lines changed

fineract-core/src/main/java/org/apache/fineract/organisation/monetary/domain/Money.java

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -254,16 +254,14 @@ public Money plus(final BigDecimal amountToAdd, MathContext mc) {
254254
if (amountToAdd == null || amountToAdd.compareTo(BigDecimal.ZERO) == 0) {
255255
return this;
256256
}
257-
final BigDecimal newAmount = this.amount.add(amountToAdd);
258-
return Money.of(getCurrencyData(), newAmount, mc);
257+
return this.plus(Money.of(this.getCurrency(), amountToAdd, mc));
259258
}
260259

261260
public Money plus(final double amountToAdd) {
262261
if (amountToAdd == 0) {
263262
return this;
264263
}
265-
final BigDecimal newAmount = this.amount.add(BigDecimal.valueOf(amountToAdd));
266-
return Money.of(getCurrencyData(), newAmount);
264+
return this.plus(Money.of(this.getCurrency(), BigDecimal.valueOf(amountToAdd), mc));
267265
}
268266

269267
public Money minus(final Money moneyToSubtract) {
@@ -298,8 +296,7 @@ public Money add(final BigDecimal amountToAdd, final MathContext mc) {
298296
if (amountToAdd == null || amountToAdd.compareTo(BigDecimal.ZERO) == 0) {
299297
return this;
300298
}
301-
final BigDecimal newAmount = this.amount.add(amountToAdd);
302-
return Money.of(getCurrencyData(), newAmount, mc);
299+
return this.plus(Money.of(this.getCurrency(), amountToAdd, mc));
303300
}
304301

305302
public Money minus(final BigDecimal amountToSubtract) {
@@ -310,8 +307,7 @@ public Money minus(final BigDecimal amountToSubtract, final MathContext mc) {
310307
if (amountToSubtract == null || amountToSubtract.compareTo(BigDecimal.ZERO) == 0) {
311308
return this;
312309
}
313-
final BigDecimal newAmount = this.amount.subtract(amountToSubtract);
314-
return Money.of(getCurrencyData(), newAmount, mc);
310+
return this.minus(Money.of(this.getCurrency(), amountToSubtract, mc));
315311
}
316312

317313
private Money checkCurrencyEqual(final Money money) {

0 commit comments

Comments
 (0)