• Post Reply Bookmark Topic Watch Topic
  • New Topic

long/int  RSS feed

 
Raj Ohadi
Ranch Hand
Posts: 316
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if there is a "long" data type, if I divide it an int like "100", will it return a long or float or double ? how will it be rounded ? just cut whatever in the decimal ? or "for decimal, 4 out 5 in rule" ?
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Basically, the narrower operand is widened to the type of the wider operand, and this is also the type of the result. If both are narrower than an int, then both are widened to type int.

Some experimentation will quickly demonstrate that integral division truncates.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!