1

Why is .* used in Java? For example

double probability = 1.*count/numdata;

gives the same output as:

double probability = count/numdata;
user4345738
  • 191
  • 9

1 Answers1

1

If count and numdata are integral: int or long the result again will be integral (integer division), so the fractions gets lost; truncated, not even rounded. As a probability is between 0.0 and 1.0, and so numdata >= count, you'll get only 0 or 1.

Simplest would be to make the division floating point:

double probability = ((double)count) / numdata;

or (more obfuscating though!)

double probability = count;
probability /= numdata;
Joop Eggen
  • 107,315
  • 7
  • 83
  • 138