Kaleb Blue
Kaleb Blue

Reputation: 507

Dividing 2 big integers in Java

I have 2 big integers that I'm working with.

BigInteger one = new BigInteger("184032000000");
BigInteger two = new BigInteger("31536000730"); //Number of milliseconds in a year, Approximately

I am trying to convert variable one(which is in millesconds) to years by dividing it by two(Approximate number of milliseconds in a year) but I can't seem to do it. I get the error: Operator '/' cannot be applied to 'java.math.BigInteger','java.math.BigInteger' I tried using long, double, BigInteger and BigDecimal in all cases, my IDE complains about some error.

My questions is "Is there a way to calculate one/two?" or once I have one(which is in milliseconds), how do I convert it to years? Thanks for the help in advance

Upvotes: 0

Views: 219

Answers (1)

James
James

Reputation: 2834

BigIntegers are immutable, which means when you do operations on them you need to create new ones. Maybe try this?

BigInteger one = new BigInteger("184032000000");
BigInteger two = new BigInteger("31536000730"); //Number of milliseconds in a year, Approximately
BigInteger three = one.divide(two);

Upvotes: 3

Related Questions