我正在尝试添加一行单元格并在网格中的新单元格中显示总计。我正在使用 DevExpress 的 gridControl。该网格有 12 列,代表一年中的月份,我想添加月份值并在第 13 列中显示总数。
我的问题是,如果我有一个浮点值“111,22”,它将作为“111,2188”添加到数据库中,并在第 13 个单元格中显示,但没有精度。
所以,我有两个问题。第一个是“为什么将其作为 111,2188 插入数据库?”第二个问题是“为什么显示总数”。
这是我的代码...当我添加 111,2188 和 200 时会发生这种情况,我得到 211,2188 ....
private void calculate_gv_row_total(int row_index) {
float total = 0;
for (int j = 0; start_index + j < start_index + months; j++)
{
float f = float.Parse(gv.GetDataRow(row_index)[start_index + j].ToString());
total = total + f;
}
gv.GetDataRow(row_index)[total_cell_index] = total;
}
我该如何解决这些问题?我究竟做错了什么?
事实上,你的网格是高效的,它将 111,2188 舍入为 111,22。如果您想查看准确的值,请增加列宽或告诉网格精度级别。
如果您不需要那么高的精度,请使用ToString("F")
private void calculate_gv_row_total(int row_index) {
float total = 0;
for (int j = 0; start_index + j < start_index + months; j++)
{
float f = float.Parse(gv.GetDataRow(row_index)[start_index + j].ToString("F"));
total = total + f;
}
gv.GetDataRow(row_index)[total_cell_index] = total;
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)