如何以0,00格式显示价格(即100 100,00)

时间:2011-02-04 08:04:07

标签: c# devexpress

HII,

我正在使用devexpress网格控件。在我的网格中有价格标签,我希望价格列以0,00格式显示....即如果我的价格是3000那么它应该显示3.000,00 ...请帮帮我...这是winforms,而前端是c#。

4 个答案:

答案 0 :(得分:12)

DevExpress控件丰富而复杂,有很多方法可以做到这一点。

最简单的可能是设置列的显示格式如下:

gridColumn.DisplayFormat.FormatString = "N2";
gridColumn.DisplayFormat.FormatType = DevExpress.Utils.FormatType.Custom;

FormatString可以是任何.NET标准或自定义格式字符串(在MSDN或google中查找“标准数字格式字符串”,“自定义数字格式字符串”)。

答案 1 :(得分:4)

对于devexpress XtraGrid,您可以使用DevExpress.Utils.FormatInfo:

DevExpress.Utils.FormatInfo fi = new DevExpress.Utils.FormatInfo();
fi.FormatType = DevExpress.Utils.FormatType.Numeric;
fi.FormatString = "n2";
myColumn.DisplayFormat.Assign(fi);

答案 2 :(得分:3)

如果您还想加入货币符号:

decimal price = 49.99M;
string data = price.ToString("c");

答案 3 :(得分:2)

货币格式取决于系统设置,有时最好明确指定精度:

double price;
string text=price.ToString("N2"); // N3 for 3 digits , etc