# A stupid question about a calculation

Page 1 of 1

## 1 Replies - 658 Views - Last Post: 10 October 2009 - 10:12 AMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'https://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=131157&amp;s=f39b79858fffeaf14b20bc76f5b4365f&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 putha-nee

Reputation: 0
• Posts: 168
• Joined: 04-October 09

# A stupid question about a calculation

Posted 10 October 2009 - 10:06 AM

``` double z = (weight - FREE_WEIGHT) /5;

double x = Math.ceil(z);

```

If weight = 33 and FREE_WEIGHT = 10, why is z returning 4 when it should be returning 5

Ultimately, why is z passing through 4 instead of 4.6 which is what is should pass through
Is This A Good Question/Topic? 0

## Replies To: A stupid question about a calculation

### #2 macosxnerd101

• Games, Graphs, and Auctions

Reputation: 12360
• Posts: 45,474
• Joined: 27-December 08

## Re: A stupid question about a calculation

Posted 10 October 2009 - 10:12 AM

I'm guessing weight and FREE_WEIGHT are ints. Basically, since all of the operands are ints, they are calculated as such. The result is then converted to a double (after truncation) and assigned to z.

Remember, all the operands are implicitly converted based on the order of magnitude. For example, if weight was a double and FREE_WEIGHT was an int, then the value stored in FREE_WEIGHT is converted to a double. Here is the order of magnitude in descending order for numerical primitives: double, float, long, int, short, byte.