Datatype to store 20 digit number
Asked Answered
A

4

10

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.

Algetic answered 15/9, 2014 at 15:38 Comment(4)
BigInteger - when I'm trying to use new BigInteger(number), I'm getting literal of type int is out of range.Algetic
Are you doing any numeric manipulation on the number?Peck
BigInteger i = new BigInteger("48565664968483514466");Peck
@Peck - I need to convert this number to BASE36 to generate barcode.Algetic
F
15
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");
Fonzie answered 15/9, 2014 at 15:41 Comment(0)
C
4

To convert your number in base 36:

BigInteger number = new BigInteger("48565664968483514466");
String numberInBase36 = number.toString(36);
System.out.println(numberInBase36);
Clemons answered 15/9, 2014 at 15:57 Comment(0)
B
2

when I'm trying to use new BigInteger(number), I'm getting literal of type int is out of range

The syntax you are looking for is

BigInteger n = new BigInteger("48565664968483514466");

with the numeric literal as a String, since the primitive integer literals cannot hold a number this large.

Bowen answered 15/9, 2014 at 15:46 Comment(0)
P
0
BigInteger i = new BigInteger("48565664968483514466");
Peck answered 15/9, 2014 at 15:45 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.