tags:

views:

361

answers:

5

which java data type would be able to store the numerical value 9999999999 ?

+10  A: 

Your concrete example could be stored in long (or java.lang.Long if this is necessary).

If at any point you need bigger numbers, you can try java.math.BigInteger (if integer), or java.math.BigDecimal (if decimal)

Bozho
These classes are very slow, and should only be used if you really need a lot of digits. 10 digits can easily be stored in a "long." However, should you need 50 to 5000 digits, these two classes are the best way to do it.
Karl
quite correct.. I instinctively assumed that he has tried the obvious, and didn't succeed. Edited my answer so that it's correct.
Bozho
+12  A: 

You can store this in a long. A long can store a value from -9223372036854775808 to 9223372036854775807.

Ben James
cletus: point taken, have edited.
Ben James
+4  A: 

A primitive long or its java.lang.Long wrapper can also store ten digits.

Thilo
+1 A long can store 18-19 digits with absolute precision. Unless the OP indicates that they need more than this, a long is a far better choice than BigInteger.
cletus
+2  A: 

you can use long or double.

akellakarthik
A double? If the OP's example of `9999999999` is indicative, then there's no need to introduce floating-point imprecision for an integral number.
Ben James
yup ben your right but was just showing him we can use these things too. It really depends on your business requirement.
akellakarthik
A: 

In addition to all the other answers I'd like to note that if you want to write that number as a literal in your Java code, you'll need to append a L or l to tell the compiler that it's a long constant:

long l1 = 9999999999;  // this won't compile
long l2 = 9999999999L; // this will work
Joachim Sauer