将datagridview单元格格式化为2个小数位 [英] Formatting datagridview cell to 2 decimal places
本文介绍了将datagridview单元格格式化为2个小数位的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
基本上,我有一个datagridview,它显示数据表中的数据。数据表中的每个单元格都是一个带有大约10个小数点的小数,如何使用datagridview将数据显示为2个小数点?
Basically I have a datagridview which displays data from a datatable. Each cell in the datatable is a decimal with roughly 10 decimal points, how can I use the datagridview to display this data to 2 decimal points?
我已经尝试过了(我在其他问题中发现):
I have tried this (what I found in other questions):
for (int i = 0; i < this.dgvDynamics1.Columns.Count; i++)
this.dgvDynamics1.Columns[i].DefaultCellStyle.Format = "N2";
但它不起作用
如果您需要更多信息,请告诉我
If you need any more info let me know
预先感谢
推荐答案
尝试一下:
this.dgvDynamics1.Columns.Items[i].DefaultCellStyle.Format = "0.00##";
this.dgvDynamics1.Columns.Items[i].ValueType = GetType(Double)
这篇关于将datagridview单元格格式化为2个小数位的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文