Search code examples
javaprimitive

How can I store the number one trillion in Java?


I am attempting to store the number one trillion in a variable. However eclipse continues to worn that it is out of its range even when the variable type is a long.

Here is my code:

long temp = 1;

if(...){
    temp = 1000000000000;
}

If anyone has any insight into why this is occurring, I would really appreciate it.


Solution

  • try

    temp = 1000000000000L;
    

    java in 1000000000000 is recognized as int, add L to the end to make it long