如何限制datagridview列的小数长度 [英] How to limit decimal length of a datagridview column
本文介绍了如何限制datagridview列的小数长度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好...我想限制datagridview列的十进制长度..
请帮帮我
Hi all...i want to limit the decimal length of a datagridview column..
Please help me out
推荐答案
试试这个
为2位小数
try this
for 2 places of decimal
double.Parse(string.Format("{0:0.00}", Eval("Name").ToString()))
or
double.Parse(Eval("Name").ToString()).ToString("0.00")
替代方便:
设置数据字段的DataFormatString
格式:{0:F}
1234.567 - > 1234.57
格式:{0:F3}
1234.567 - > 1234.567
例如:
DataFormatString ={0:F3}
$在aspx页面设计模式下b $ b
单击gridView1
然后点击> of gridView1
然后点击'Edit Columns'
然后选择相应的字段并设置'DataFormatString'
您还可以查看以下链接
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.boundfield.dataformatstring.aspx
请告诉我,如果我困惑你
Alternate and easy way:
set the DataFormatString of Databound field
Format: {0:F}
1234.567 -> 1234.57
Format: {0:F3}
1234.567 -> 1234.567
for eg:
DataFormatString ="{0:F3}"
in aspx page design mode
single click on gridView1
then click on ">" of gridView1
then click on 'Edit Columns'
then select respective field and set 'DataFormatString'
you can also view the following link
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.boundfield.dataformatstring.aspx
please tell me if i m confusing you
嘿那里,
有一段时间有类似的问题...
VB代码限制小数:
Me.DataGridView1.Columns.Item(3).DefaultCellStyle.Format =n2
C#代码:
dataGridView2.Columns [Column_Name]。DefaultCellStyle.Format =n2;
Hey there,
Had a similar issue a while back...
VB Code to limit decimal:
Me.DataGridView1.Columns.Item(3).DefaultCellStyle.Format = "n2"
C# Code:
dataGridView2.Columns["Column_Name"].DefaultCellStyle.Format = "n2";
这篇关于如何限制datagridview列的小数长度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文