Skip to content

Commit

Permalink
Merge pull request #34 from bloxbean/fix_33
Browse files Browse the repository at this point in the history
fix: If ArithimaticException, use scale=10 and try again
  • Loading branch information
satran004 authored Oct 16, 2023
2 parents 2d05ae1 + 1b2d8ee commit 888ddb3
Showing 1 changed file with 6 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import java.io.ByteArrayOutputStream;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.math.RoundingMode;

public class CborSerializationUtil {

Expand Down Expand Up @@ -87,7 +88,11 @@ public static BigDecimal toRationalNumber(DataItem di) {
Number numerator = rdi.getNumerator();
Number denominator = rdi.getDenominator();

return new BigDecimal(numerator.getValue()).divide(new BigDecimal(denominator.getValue()));
try {
return new BigDecimal(numerator.getValue()).divide(new BigDecimal(denominator.getValue()));
} catch (ArithmeticException e) { //set scale and try again
return new BigDecimal(numerator.getValue()).divide(new BigDecimal(denominator.getValue()), 10, RoundingMode.HALF_UP);
}
}

/**
Expand Down

0 comments on commit 888ddb3

Please sign in to comment.