Variables and operatorsInteger division
Dividing integers
When both operands are integers, division discards the fractional part. Storing the result in a floating-point variable afterwards cannot recover it.
Code example
double a = 5 / 2;
double b = 5.0 / 2; Walkthrough
a holds 2.0 and b holds 2.5. The second expression uses a floating-point operand before division.