So I'm trying to divide two BigIntegers 22 and 7. In other words, I'm trying to store the first few decimals of b1.divide(b2)
[where b1 = new BigInteger("22")
, and b2 = new BigInteger("7")
] into some datatype. However, if I use a BigDecimal
, it shows an irrepresentable number error, while it doesn't even work for doubles. What should I do? For your convenience, here's the code:
BigInteger b1 = new BigInteger("22");
BigInteger b2 = new BigInteger("7");
BigInteger b3 = b1.divide(b2);
System.out.println(b3);
And here's what shows up in the console:
Exception in thread "main" java.lang.ArithmeticException: Non-terminating decima
l expansion; no exact representable decimal result.
at java.math.BigDecimal.divide(Unknown Source)
at Divider.main(Divider.java:13)