Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java: divide two BigInteger Objects into a BigDecimal object

What is the easiest way, using the least amount of unnecessary overhead to divide two BigInteger objects and store it in a BigDecimal Object?

I have been trying to work around the problem and cannot find anything that does not use an extremely excessive amount of conversions.

Edit: Realized how stupid this question was, I'll leave it up for reference though

like image 935
Samuel French Avatar asked Jun 25 '13 00:06

Samuel French


1 Answers

You can convert your BigIntegers into BigDecimals:

// bigIntX is a BigInteger
BigDecimal bigDecX = new BigDecimal(bigIntX);
BigDecimal bigDecY = new BigDecimal(bigIntY);

// to divide:
bigDecX.divide(bigDecY);
like image 181
jh314 Avatar answered Oct 10 '22 09:10

jh314