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!

Java Long Multiplcation Error

Status
Not open for further replies.
Oct 2, 2007
15
US
Why does the statement long x = 24 * 60 * 60 * 1000 * 1000 compute the value for x to equal 500654080 instead of what it really is 86400000000?

Thanks,

 
Because, by default, numbers without decimal point are considered ints, so you're multiplying ints and then storing the result in a long. But the result is bigger than maximun int, so you start over zero again.

Try this

Code:
long y = 24L * 60L * 60L * 1000L * 1000L ;

Cheers,
Dian
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top