如何将数据网格视图单元格格式化为%或正确写入公式

本文关键字:格式化 数据 数据网 网格 单元格 视图 | 更新日期: 2023-09-27 18:19:37

我正在开发一个评估应用程序,我很难写出公式,给出如下所需的结果:

                 Quantity / Production * Non productive % = Labor Hours

上述公式的数学答案如下:

                 1000 SF /  300 SF per hour *  @10% Non Productive= 3.6 Labor hours

我的问题是如何写一个公式来正确计算工时?

谢谢

这是我的代码:

    private void dgv1_CellEndEdit(object sender, DataGridViewCellEventArgs e)
         {
                double cell2 = Convert.ToSingle(dgv1.CurrentRow.Cells[2].Value);
                double cell4 = Convert.ToSingle(dgv1.CurrentRow.Cells[4].Value);
                double cell5 = Convert.ToSingle(dgv1.CurrentRow.Cells[5].Value);
                double cell6 = Convert.ToSingle(dgv1.CurrentRow.Cells[6].Value);
                double cell7 = Convert.ToSingle(dgv1.CurrentRow.Cells[7].Value);
                double cell8 = Convert.ToSingle(dgv1.CurrentRow.Cells[8].Value);
                double cell9 = Convert.ToSingle(dgv1.CurrentRow.Cells[9].Value);
                double cell10 = Convert.ToSingle(dgv1.CurrentRow.Cells[10].Value);
                double cell11 = Convert.ToSingle(dgv1.CurrentRow.Cells[11].Value);
                double cell12 = Convert.ToSingle(dgv1.CurrentRow.Cells[12].Value);
                double cell13 = Convert.ToSingle(dgv1.CurrentRow.Cells[13].Value);
                double cell14 = Convert.ToSingle(dgv1.CurrentRow.Cells[14].Value);
                double cell15 = Convert.ToSingle(dgv1.CurrentRow.Cells[15].Value);
                double cell16 = Convert.ToSingle(dgv1.CurrentRow.Cells[16].Value);
                double cell17 = Convert.ToSingle(dgv1.CurrentRow.Cells[17].Value);
                if (2.ToString() != "" && cell4.ToString() != "" && cell5.ToString() != "" && cell6.ToString() != "" && cell7.ToString() != "" && cell8.ToString() != "" && cell9.ToString() != "" && cell10.ToString() != "" && cell11.ToString() != "" && cell12.ToString() != "" && cell13.ToString() != "" && cell14.ToString() != "" && cell15.ToString() != "" && cell16.ToString() != "" && cell17.ToString() != "")
    {
        dgv1.CurrentRow.Cells[6].Value = cell2 / cell4 * cell5;   // <------ This is the formula I'm talking about//
        dgv1.CurrentRow.Cells[10].Value = cell6 * cell7 *cell8 *cell9;
        dgv1.CurrentRow.Cells[13].Value = cell2 / cell11;
        dgv1.CurrentRow.Cells[17].Value = cell13 * cell14 * cell15 * cell16;
    }
}

如何将数据网格视图单元格格式化为%或正确写入公式

Quantity / (Production * ((Non productive / Total)* 100) ) = Labor Hours

根据您的代码,我假设cell2是数量,cell4是生产,cell5是非生产。

你需要做的第一件事是找出如何计算非生产性百分比。我认为(这意味着我不确定)它应该由(Non productive / Total)* 100计算,根据我的假设,我们是非生产性的cell5,尽管我不知道总数在哪里。

那么你的公式是:

cell2 / ( cell4 * ((cell5 / total) * 100 )))