Linked Questions

Popular Questions

Average comparison

Asked by At

I'm working on this Java project that calculates the average of numbers. Everything seems to be working fine after I populated it with some dummy input.

However, I realized that when I change the positions of same numbers, I get different results.

For instance average of {3.1, 4.7, 5.2, 14.4, 1.1} is 5.7
And average of {3.1, 4.7, 14.4, 1.1, 5.2} is 5.700000000000001.

This makes the comparator return false when comparing some of these numbers (even the ones I have prior knowledge of the result)

Is there something I'm missing?

Related Questions