I'm getting "integer number too large: 1000000000001" for the following code line. How do I make it so that maxValue开发者_StackOverflow中文版 can hold 1 quadrillion or 1 trillion?
long maxValue = 1000000000001; //1,000,000,000,001
You need to use a long literal (with an L
at the end):
long maxValue = 1000000000001L; //1,000,000,000,001
Note that you don't need to use BigInteger if your numbers are between -263 and 263-1 (inclusive). (263-1 = 9223372036854775807L = 0x7fffffffffffffffL.)
This answer is complete.
Java Language Specification:
An integer literal is of type long if it is suffixed with an ASCII letter L or l (ell); otherwise it is of type int (§4.2.1).
You may check for another question and answer before you ask. Someone probably has the same question and got the best answer. See this:
Large Numbers in Java
This is probably what you need.
精彩评论