Skip to content

Commit

Permalink
quickly detects that BigDecimal is integer
Browse files Browse the repository at this point in the history
  • Loading branch information
fengyizhu committed Nov 15, 2022
1 parent 0aadabd commit 9607eda
Showing 1 changed file with 7 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -460,11 +460,13 @@ public Number narrow(Number number) {
if(number instanceof BigDecimal) {

final BigDecimal decimal = ((BigDecimal) number);
try {
BigInteger integer = decimal.toBigIntegerExact();
return narrow(integer);
} catch (ArithmeticException e) {
return number; // cannot narrow to integer
if(decimal.scale()<=0) {
try {
BigInteger integer = decimal.toBigIntegerExact();
return narrow(integer);
} catch (ArithmeticException e) {
return number; // cannot narrow to integer
}
}
}

Expand Down

0 comments on commit 9607eda

Please sign in to comment.