4

I'm getting "integer number too large: 1000000000001" for the following code line. How do I make it so that maxValue can hold 1 quadrillion or 1 trillion?

long maxValue = 1000000000001;      //1,000,000,000,001
adarshr
  • 59,379
  • 22
  • 134
  • 163
Riddick51PB
  • 41
  • 1
  • 2

3 Answers3

10

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.)

Ted Hopp
  • 227,407
  • 48
  • 383
  • 507
  • 2
    Actually `2^63` = 9 223 372 036 854 775 808 (10) = 8000000000000000 (16). Max value is `2^63 - 1` (because of two's complement binary representation). – Grzegorz Szpetkowski Jul 24 '11 at 19:00
2

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).

Alireza Noorali
  • 3,777
  • 2
  • 26
  • 71
0

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.

Community
  • 1
  • 1
Kristiono Setyadi
  • 5,590
  • 1
  • 18
  • 28