Quantcast
Channel: Windows Forms Data Controls and Databinding forum
Viewing all articles
Browse latest Browse all 2535

Summing error

$
0
0
Hi,
I have this code which i cant get the correct sum. Sum always getting + - 5 
private void AverageYieldToolStripMenuItem_Click(object sender, EventArgs e)
        {
            float sum = 0;
            float avg = 0;
            int dataCount = 0;

            for (int row = 0; row <= dataGridView1.Rows.Count - 1; row++) 
            {
                dataCount++;
                sum += float.Parse(dataGridView1.Rows[0].Cells[1].Value.ToString());
            }
            avg = (sum / dataCount);
            textBox1.Text = avg.ToString("00.00");
            textBox2.Text = dataCount.ToString("00");
            textBox3.Text = sum.ToString("00.00");
        }
Thanks



Viewing all articles
Browse latest Browse all 2535

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>