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
2009-12-21 08:23:46
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
2009-12-21 08:32:26
quite correct.. I instinctively assumed that he has tried the obvious, and didn't succeed. Edited my answer so that it's correct.
Bozho
2009-12-21 08:36:43
+12
A:
You can store this in a long. A long can store a value from -9223372036854775808 to 9223372036854775807.
Ben James
2009-12-21 08:27:03
+4
A:
A primitive long or its java.lang.Long wrapper can also store ten digits.
Thilo
2009-12-21 08:27:55
+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
2009-12-21 08:32:50
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
2009-12-21 08:56:10
yup ben your right but was just showing him we can use these things too. It really depends on your business requirement.
akellakarthik
2009-12-21 09:01:40
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
2010-02-17 10:12:58