Java – How to divide so I get a decimal value


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


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?

Best Solution

quotient = 3 / 2;
remainder = 3 % 2;

// now you have them both