How do I divide so I get a decimal value?

Raja picture Raja · Mar 20, 2009 · Viewed 130.2k times · Source

I want to know how to get remainder and quotient in single value in Java.

Example:

3/2 I should get value as 1.5.

If I use the / operator I get only the quotient. If I user the % operator I get only the remainder. How do I get both at a time in the same variable?

Answer

recursive picture recursive · Mar 20, 2009
quotient = 3 / 2;
remainder = 3 % 2;

// now you have them both