0

I'm trying to get a number when I divide 2 numbers together:

int wins = 3070;
int n = 10000;
double probability = wins/n;
System.out.println(probability);

All it prints is: 0.0

But I'm expecting it to print: 0.307

  • Convert either of the int to a double to do a double division(that returns a decimal value). In kotlin its done by `toDouble()`, probably its casting in java (not sure). And you can shorten it till 3 digit by string templating or by multiplying by 1000 and then truncate/round and then divide by 1000. – Animesh Sahu May 10 '20 at 04:42

1 Answers1

1

Atleast one of the values (numerator or denominator) should be type casted with double. Integer divided by integer would result integer. If one of them would be double then result would be upcasted to double. Try it! It should work!