title: why is the math calculations in java are not precise?
body: <p>i have an XYSeries that holds Lat and Lon position of points.
  in some point i calculate the center point of all those positions.
  the code is very simple:</p>
  
  <pre><code>for(int i = 0; i &lt; pnts.getItemCount(); i++){
                  avgLon += (double)pnts.getX(i);
                  avgLat += (double)pnts.getY(i);
              }
              cntrMass = new Vector2D(avgLon/pnts.getItemCount(), avgLat/pnts.getItemCount());
  </code></pre>
  
  <p>however this average calculation is not precise.
  when i calculate the same thing using excel sheet and the same data set there is a difference in the center point. I am using the exact number of significant digits for both calculations.
  the differences is of a 1e-6 magnitude, when converted to meters it gets pretty significant.
  any idea of how to fix this problem? any help would be appreciated. </p>