Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Long is showing up as negative. Why?

Status
Not open for further replies.

LucL

Programmer
Jan 23, 2006
117
US
I feel silly asking this but I am not sure what the problem is.

long max_daily_bytes2 = 10 * (1024 * 1024 * 1024);
System.out.println(max_daily_bytes2);

Output:

-2147483648

What's causing this? Java longs should have a range of up to 9,223,372,036,854,775,807

Thanks!
 
Because the numeric literals are default ints in Java. Try someting like this:
Code:
long max_daily_bytes2 = ((long) 10) * (1024 * 1024 * 1024);
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top