• Post Reply Bookmark Topic Watch Topic
  • New Topic

float confusion  RSS feed

 
catherine matthews
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please explain why
float y =( 32 / 10 * 3 )- gives me a 9.0, not 32
as i thought that by default it computes the value as integer
since no f is specified....


the output is

z is 30.0
y is 9.0
the answer is 3.0
 
Peter Chase
Ranch Hand
Posts: 1970
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
32/10*3 is evaluated using integers, left-to-right. So, 32/10 is 3. Then, 3*3 is 9. Then convert to float: 9.0
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!