I need to compute probability of an integer and a long. but I always get 0.
int a = 234;
long b = 123453344L
float c = a /b;
How to get it right in Java?
You need to either cast one of them as a float, or declare one of the variables to be a float from the start. Otherwise, Java's integer division takes over, and just as an int divided by an int must be an int, that would apply to longs as well.
float c = (float) a / b;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With