Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Number too big for BigInteger

I'm developing a chemistry app, and I need to include the Avogadro's number: (602200000000000000000000)

I don't really know if I can use scientific notation to represent it as 6.022 x 10x23 (can't put the exponent).

I first used double, then long and now, I used java.math.BigInteger.

But it still says it's too big, what can I do or should this is just to much for a system?

like image 414
Antonio Aguilar Avatar asked Nov 28 '22 04:11

Antonio Aguilar


1 Answers

Pass it to the BigInteger constructor as a String, and it works just fine.

BigInteger a = new BigInteger("602200000000000000000000");
a = a.multiply(new BigInteger("2"));
System.out.println(a);

Output: 1204400000000000000000000

like image 132
xrisk Avatar answered Dec 05 '22 18:12

xrisk