I have a HashMap
called List
whose size
is 234
wordFreqMap = {radiology
what you are doing is dividing an integer by another integer and then trying to cast that to a double. int/int is a int do though you cast that to a double you will not get the actual value with decimal points.
int/int -> int
What you should do is either cast word.getValue() or noOfterms to double then
int/double -> double
double/int -> double
double/double -> double
e.g.
tf = (double)word.getValue()/noOfTerms;
or
tf = word.getValue()/(double)noOfTerms;
You are doing integer division and then casting that answer to a double. What you need to do is cast one of the two values to a double first, and then do division on it. That should get you the answer you desire.
Integer/Integer
is an Integer
which is casted to a Double
so ,it remains an Integer
expanded to a Double
.
Change it to
tf = ( (double)word.getValue() / noOfTerms );
You're performing an integer division and then type casting:
tf = (double) ( word.getValue() / noOfTerms );
^-----integer division----^
Type cast one of the elements in the division to convert into a floating point division:
tf = ((double)word.getValue()) / noOfTerms;