Skip to content

Commit

Permalink
fix: If ArithimaticException, use scale=10 and try again
Browse files Browse the repository at this point in the history
  • Loading branch information
satran004 committed Oct 16, 2023
1 parent 2d05ae1 commit 1b2d8ee
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 1b2d8ee

Please sign in to comment.