Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to assign very large numbers to variable in java?

Tags:

java

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
like image 722
Riddick51PB Avatar asked Dec 17 '22 11:12

Riddick51PB


1 Answers

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

like image 94
Ted Hopp Avatar answered Jan 18 '23 05:01

Ted Hopp