Dividing doubles 10 by 13 gives 0?

Why doesn't this work??

int ri is 10
int tot is 13

Basically, what I want to do is assign 10/13 ( or ri / tot) to a variable. Everything I've tried (BigDecimal, double, float) have all come out to 0.

The following variables come out to 0 when run as-is:

  • formatted

  • actualPercent

  • tryDivide

  • percent


Here's my code:

this is really, really weird, and any help would be greatly appreciated.

---
Original message URL: http://www.jetbrains.net/devnet/message/5233071#5233071

1 comment
Comment actions Permalink

Both ru and tot are integers. The result of a division of two ints is an int which is rounded towards 0.

Try something like (double)ri / (double)tot or make both into floats or doubles.

I think that this isn't the right place for Java question, though.
Wallaby

0

Please sign in to leave a comment.