Reputation: 64854
I need to perform division between integers in Java, and the result should be a float.
Could I just use /
symbol for it? As in:
int integer1 = 1;
int integer2 = 2;
float quotient = integer1 / integer2; // Could I do this?
Upvotes: 8
Views: 29476
Reputation: 6334
Cast one of the integers to float to ensure a floating point division:
float result = integer1 / (float) integer2
Upvotes: 25