Incorrect division result with double value

961 views Asked by At

I have a problem doing a division. I have this chunk of code, where this operation must be 40.4239, but instead i have this result: 0.005595493389623997
I can understand the amount of decimals, I have to solve that with decimalFormat, but I can't understand this result...
contTotal is 288975 in this case, so: (288975/714861)*100 = 40.4239
Any idea...?

int contTotal = 0;  
double result = 0;
    for(DoubleWritable val : valores) {
        contTotal += val.get();
    }
    result = (contTotal/714861) *100; 
2

There are 2 answers

0
Xdsasdf On BEST ANSWER

Don't know if this helps, but it really looks like you're doing the division twice, since (40.423/714861)*100 is actually 0.005595493389623997. I would definitely check that.

4
hs2345 On

You could do something like:

double z = (288975.0/714861.0)*100.0;