aspose file tools*
The moose likes Beginning Java and the fly likes problem with variable Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "problem with variable" Watch "problem with variable" New topic
Author

problem with variable

Dominic Griffin
Greenhorn

Joined: Jun 10, 2009
Posts: 16
I am trying to calculate occupancy the occupancy rate of an hotel. The expression is returning a zero. Does anyone see an obvious solution?


Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 19073
    
  40

The variables on the right are ints, so when you do the division, it will truncate the non-integer portion. The variable that you are assigning to is also an int, and hence, can't hold the non-integer portion.

It may be a good idea to cast to floating point before doing the division -- and assign it to a floating point variable.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Fred Hamilton
Ranch Hand

Joined: May 13, 2009
Posts: 679
In other words, your program has only two possibilities. Hotel is full, or hotel is empty.
Dominic Griffin
Greenhorn

Joined: Jun 10, 2009
Posts: 16
The lightbulb just clicked. It all makes sense now. Thank you gentlemen!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: problem with variable