Data type for storing a 20-digit number

I have 20 digits, what data type will this number support? I tried long, double, but I'm out of range.

Number = 48565664968483514466

Then I need to convert this number to Base36 in order to generate a barcode.

+6
source share
4 answers
BigInteger: 

The BigInteger class allocates as much memory as is needed to store all the bits of data that it requests, and also provides analogues of operations with all the primitive Java operators and all the corresponding methods from java.lang.Math.

Declare it as

 BigInteger bi1 = new BigInteger("12345678900123"); 
+13
source

To convert your number to base 36:

 BigInteger number = new BigInteger("48565664968483514466"); String numberInBase36 = number.toString(36); System.out.println(numberInBase36); 
+2
source

when I try to use the new BigInteger (number), I get an int literal out of range

The syntax you are looking for is

 BigInteger n = new BigInteger("48565664968483514466"); 

with a numeric literal like String , since primitive integer literals cannot contain a large number.

+1
source
 BigInteger i = new BigInteger("48565664968483514466"); 
0
source

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


All Articles