Skip to content

Commit

Permalink
scale -1 is ignored in context;
Browse files Browse the repository at this point in the history
TCK: still 14 tests failing
  • Loading branch information
oboehm committed Aug 22, 2018
1 parent 3fc37e6 commit ed7defb
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/main/java/de/jfachwert/bank/Geldbetrag.java
Expand Up @@ -945,11 +945,16 @@ private static BigDecimal toBigDecimal(Number value, MonetaryContext monetaryCon
if (roundingMode == null) {
roundingMode = RoundingMode.HALF_UP;
}
BigDecimal scaled = n.setScale(monetaryContext.getMaxScale(), roundingMode);
if (scaled.compareTo(n) != 0) {
throw new LocalizedArithmeticException(value, "lost_precision");
int scale = monetaryContext.getMaxScale();
if (scale < 0) {
return n;
} else {
BigDecimal scaled = n.setScale(scale, roundingMode);
if (scaled.compareTo(n) != 0) {
throw new LocalizedArithmeticException(value, "lost_precision");
}
return scaled;
}
return scaled;
}

/**
Expand Down

0 comments on commit ed7defb

Please sign in to comment.