Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Datatype to store 20 digit number

I have a number of 20 digit, which datatype will support to store this number? I have tried long, double but I 'm getting out of range.

Number = 48565664968483514466

Then I have to convert this number to Base36 to generate the barcode.

like image 607
DeepVeen Avatar asked Sep 15 '14 15:09

DeepVeen


2 Answers

BigInteger:

The BigInteger class allocates as much memory as it needs to hold all the bits of data it is asked to hold and also provides operations analogues to all of Java's primitive integer operators and for all relevant methods from java.lang.Math.

Declare it as

BigInteger bi1 =  new BigInteger("12345678900123");
like image 196
kirti Avatar answered Sep 29 '22 06:09

kirti


To convert your number in base 36:

BigInteger number = new BigInteger("48565664968483514466");
String numberInBase36 = number.toString(36);
System.out.println(numberInBase36);
like image 43
assylias Avatar answered Sep 29 '22 04:09

assylias