Click here to Skip to main content
15,907,281 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
am trying to multiply the value in one cell to another cell and display the answer in
another cell. it is working alright but it does not display answers which are decimals but
display them to the nearest whole number
e.g. 3 * 1.5 will be 5 instead of 4.5
please help me out


C#
for (int i = 0; i < dgvSales.Rows.Count - 1; i++)
            {
                //this.dgvSales.Rows[i].Cells["Quantity Sold"].Value = 0;
                this.dgvSales.Rows[i].Cells["Amount"].Value = Convert.ToDouble   
                (dgvSales.Rows[i].Cells["Quantity Sold"].Value) * Convert.ToDouble
                (dgvSales.Rows[i].Cells["Unit Price"].Value);

            }
Posted

1 solution

C#
for (int i = 0; i < dgvSales.Rows.Count - 1; i++)
{
    double a = Convert.ToDouble(dgvSales.Rows[i].Cells["Quantity Sold"].Value);
    double b = Convert.ToDouble(dgvSales.Rows[i].Cells["Unit Price"].Value);
    this.dgvSales.Rows[i].Cells["Amount"].Value = (a * b).ToString("0.00");
}
 
Share this answer
 
Comments
mikeoabban 8-Aug-13 10:03am    
i tried it but still does not display the answers in decimals but
display them to the nearest whole number

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900