将单元格中的值乘以另一个单元格并在另一个单元格中显示答案

将单元格中的值乘以另一个单元格并在另一个单元格中显示答案

问题描述:

我试图将一个单元格中的值乘以另一个单元格,并在另一个单元格中显示答案。它工作正常,但它不显示小数的答案,但是

将它们显示为最接近的整数

,例如3 * 1.5将是5而不是4.5

请帮帮我





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


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);

            }

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");
}