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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Question about Interger.MAX_VALUE

Status
Not open for further replies.

kshea

Technical User
May 31, 2002
60
CA
Hello All,

I am trying to compare a long value with Inter.MAX_VALUE*2, like
long lNum = Long.parseLong("222");
if(lNum <= (Interger.MAX_VALUE*2))
{
// Do something;
}
But the if condition always return false. Interger.MAX*2 will give me an int, converting int to long is widen conertion and should be fine. I don't know what I am missing here. Could anyone give me a hint?

Thank you
 
Actually the widening conversion does not take place. Since MAX_VALUE (7FFFFFFF) multiplied by 2 make the int a negative number the condition will always fail for a positive lNum. Try forcing the widening like this:
if(lNum <= (Integer.MAX_VALUE*2L)) {
// Do something;
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top