BigInteger.valueOf () for very large numbers?

What would be the best way to convert a 50 digit string to BigInteger in Java? It does not have a valueOf (String) method, and I cannot convert it to Long because it is too small.

+3
source share
4 answers

It has a constructor BigInteger(String): -)

String S = "12345678901234567890123456789012345678901234567890";
BigInteger bi = new BigInteger(S);
+14
source

What about...

BigInteger bi = new BigInteger(my50DigitString);

Xxx.valueOf() , . , , . , valueOf() - , , -, BigInteger.valueOf(String). .

+2

BigInteger has a constructor that accepts a string.

+1
source

You tried

BigInteger i = new BigInteger(s);
+1
source

Source: https://habr.com/ru/post/1716256/


All Articles