Skip to content

Commit

Permalink
improve number type
Browse files Browse the repository at this point in the history
  • Loading branch information
Alanscut committed Jan 15, 2020
1 parent 588d61e commit 6ff06c2
Showing 1 changed file with 3 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ public Object unwrap(final Object o) {

private static boolean isPrimitiveNumber(final Number n) {
return n instanceof Integer ||
n instanceof Float ||
n instanceof Double ||
n instanceof Long ||
n instanceof BigDecimal ||
Expand All @@ -97,9 +98,9 @@ private static Number unwrapNumber(final Number n) {
if (!isPrimitiveNumber(n)) {
BigDecimal bigDecimal = new BigDecimal(n.toString());
if (bigDecimal.scale() <= 0) {
if (bigDecimal.compareTo(new BigDecimal(Integer.MAX_VALUE)) <= 0) {
if (bigDecimal.abs().compareTo(new BigDecimal(Integer.MAX_VALUE)) <= 0) {
unwrapped = bigDecimal.intValue();
} else if (bigDecimal.compareTo(new BigDecimal(Long.MAX_VALUE)) <= 0){
} else if (bigDecimal.abs().compareTo(new BigDecimal(Long.MAX_VALUE)) <= 0){
unwrapped = bigDecimal.longValue();
} else {
unwrapped = bigDecimal;
Expand Down

0 comments on commit 6ff06c2

Please sign in to comment.