将单元格中的值乘以另一个单元格并在另一个单元格中显示答案 [英] multipling value in a cell to another cell and displaying the answer in another cell

查看:201
本文介绍了将单元格中的值乘以另一个单元格并在另一个单元格中显示答案的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

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


这篇关于将单元格中的值乘以另一个单元格并在另一个单元格中显示答案的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆